3 ms·
What is the benefit to having 'this' defined based on where a function is executed rather than where it is created? Is this mainly an artifact of the ability t
by nitrogen 16y ago
What is the benefit to having 'this' defined based on where a function is executed rather than where it is created? Is this mainly an artifact of the ability to assign a function created in one place to an object created elsewhere?
- munificent 16y agoIt allows you to inherit functions from a prototype and still have them execute against the current receiver. Consider: var base = { greet: function() { log('my name is ' + this.name); }, name: 'base' } var derived { __proto__: base, name: 'derived' } derived.greet(); If the greet function was bound at creation time to base, then the last line would print "my name is base" instead of the desired "my name is derived".