diff --git a/lib/nodes.js b/lib/nodes.js index e97366d1..48629a27 100644 --- a/lib/nodes.js +++ b/lib/nodes.js @@ -7,17 +7,7 @@ child.prototype = new ctor; child.__super__ = parent.prototype; return child; - }, __bind = (Function.prototype.bind ? Function.prototype.call.bind(Function.prototype.bind) : function(fn, me){ - return function bound(){ - if (!(this instanceof bound)) - return fn.apply(me, arguments); - var ctor = function(){}; - ctor.prototype = fn.prototype; - var obj = new ctor(); - fn.apply(obj, arguments); - return obj; - }; - }), __indexOf = Array.prototype.indexOf || function(item) { + }, __bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; }, __indexOf = Array.prototype.indexOf || function(item) { for (var i = 0, l = this.length; i < l; i++) { if (this[i] === item) return i; } @@ -2258,7 +2248,7 @@ }; UTILITIES = { "extends": 'function(child, parent) {\n for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; }\n function ctor() { this.constructor = child; }\n ctor.prototype = parent.prototype;\n child.prototype = new ctor;\n child.__super__ = parent.prototype;\n return child;\n}', - bind: ' (Function.prototype.bind ? Function.prototype.call.bind(Function.prototype.bind) : function(fn, me){\n return function bound(){\n if (!(this instanceof bound))\n return fn.apply(me, arguments);\n var ctor = function(){};\n ctor.prototype = fn.prototype;\n var obj = new ctor();\n fn.apply(obj, arguments);\n return obj;\n };\n})', + bind: 'function(fn, me){ return function(){ return fn.apply(me, arguments); }; }', indexOf: 'Array.prototype.indexOf || function(item) {\n for (var i = 0, l = this.length; i < l; i++) {\n if (this[i] === item) return i;\n }\n return -1;\n}', hasProp: 'Object.prototype.hasOwnProperty', slice: 'Array.prototype.slice' diff --git a/src/nodes.coffee b/src/nodes.coffee index 2a694f08..73a60dad 100644 --- a/src/nodes.coffee +++ b/src/nodes.coffee @@ -1769,17 +1769,7 @@ UTILITIES = # Create a function bound to the current value of "this". bind: ''' - (Function.prototype.bind ? Function.prototype.call.bind(Function.prototype.bind) : function(fn, me){ - return function bound(){ - if (!(this instanceof bound)) - return fn.apply(me, arguments); - var ctor = function(){}; - ctor.prototype = fn.prototype; - var obj = new ctor(); - fn.apply(obj, arguments); - return obj; - }; - }) + function(fn, me){ return function(){ return fn.apply(me, arguments); }; } ''' # Discover if an item is in an array. diff --git a/test/classes.coffee b/test/classes.coffee index 4ba57d19..44f9e1d9 100644 --- a/test/classes.coffee +++ b/test/classes.coffee @@ -431,12 +431,10 @@ test "`new` shouldn't add extra parens", -> test "`new` works against bare function", -> - nonceA = {} - nonceB = null - eq nonceA, new -> - eq (new => nonceB = this), nonceB - notEqual this, new => this - nonceA + + eq Date, new -> + eq this, new => this + Date test "#1182: a subclass should be able to set its constructor to an external function", ->