Skip to content

Commit

Permalink
Merge branch '1.3-bind-proposal'
Browse files Browse the repository at this point in the history
  • Loading branch information
cpojer committed Aug 30, 2010
2 parents 6312f84 + 6d6b481 commit aa8d931
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 8 deletions.
2 changes: 1 addition & 1 deletion Source/Core/Core.js
Expand Up @@ -267,7 +267,7 @@ force('String', String, [
])('Number', Number, [
'toExponential', 'toFixed', 'toLocaleString', 'toPrecision'
])('Function', Function, [
'apply', 'call'
'apply', 'call', 'bind'
])('RegExp', RegExp, [
'exec', 'test'
])('Object', Object, [
Expand Down
29 changes: 22 additions & 7 deletions Source/Types/Function.js
Expand Up @@ -32,14 +32,15 @@ Function.implement({
attempt: function(args, bind){
try {
return this.apply(bind, Array.from(args));
} catch (e){
return null;
}
} catch (e){}

return null;

This comment has been minimized.

Copy link
@fabiomcosta

fabiomcosta Aug 30, 2010

Member

common makes no difference at all...

This comment has been minimized.

Copy link
@sebmarkbage

sebmarkbage Aug 30, 2010

Member

++

This comment has been minimized.

Copy link
@cpojer

cpojer Aug 30, 2010

Author Member

it is exactly the same as before and makes more clear that we always return null.

This comment has been minimized.

Copy link
@cpojer
},

bind: function(bind, args){
var self = this;
if (args != null) args = Array.from(args);
bind: function(bind){
var self = this,
args = (arguments.length > 1) ? Array.slice(arguments, 1) : null;

return function(){
return self.apply(bind, args || arguments);
};
Expand All @@ -50,7 +51,11 @@ Function.implement({
},

pass: function(args, bind){
return this.bind(bind, args);
var self = this;
if (args != null) args = Array.from(args);
return function(){
return self.apply(bind, args || arguments);
};
},

periodical: function(periodical, bind, args){
Expand All @@ -65,8 +70,18 @@ Function.implement({

//<1.2compat>

delete Function.prototype.bind;

Function.implement({

bind: function(bind, args){
var self = this;
if (args != null) args = Array.from(args);
return function(){
return self.apply(bind, args || arguments);
};
},

create: function(options){
var self = this;
options = options || {};
Expand Down

2 comments on commit aa8d931

@ibolmo
Copy link
Member

@ibolmo ibolmo commented on aa8d931 Aug 30, 2010

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In regards to #bind. Since we're now following spec/prototypejs then we should consider this optimization: https://prototype.lighthouseapp.com/projects/8886-prototype/tickets/215

Take a look at the charts, it's a "dramatic" improvement.

@cpojer
Copy link
Member Author

@cpojer cpojer commented on aa8d931 Aug 30, 2010

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would you mind doing the fix and sending a pull request? :)

Please sign in to comment.