olivernn / augment.js

Modern JavaScript in your IE
https://olivernn.github.io/augment.js/
MIT License
431 stars 31 forks source link

ES5 bind #12

Closed Raynos closed 12 years ago

Raynos commented 12 years ago
bound = function () {
    return self.apply( nop.prototype && this instanceof nop ? this : ( obj || {} ),
        args.concat( slice.call(arguments) ) );
};

http://es5.github.com/#x15.3.4.5

Set the [[Construct]] internal property of F as described in 15.3.4.5.2.

http://es5.github.com/#x15.3.4.5.2

Return the result of calling the [[Construct]] internal method oftarget providing args as the arguments.

http://es5.github.com/#x13.2.2

Return obj.

Basically your code always returns the return value of the bound function and doesn't handle cases like

new ( (function () {
  return undefined;
}).bind(lulz, args) ) !== undefined;

Here the return value of invoking new (and [[Construct]]) on the bound function should be that the new instance is returned, not the return value of the bound function.

Again see es5-shim for implementation.

olivernn commented 12 years ago

Included in the latest version