mirror of
https://github.com/jashkenas/coffeescript.git
synced 2026-05-03 03:00:14 -04:00
modified shorter imlementation of bind
This commit is contained in:
@@ -12,11 +12,8 @@
|
||||
(to < 0 ? to + array.length : to || array.length) + (exclusive ? 0 : 1)
|
||||
];
|
||||
}, __bind = function(func, obj, args) {
|
||||
obj = obj || {};
|
||||
return (typeof args !== 'undefined' && args !== null) ? function() {
|
||||
return func.apply(obj, args.concat(__slice.call(arguments, 0)));
|
||||
} : function() {
|
||||
return func.apply(obj, arguments);
|
||||
return function() {
|
||||
return func.apply(obj || {}, args ? args.concat(__slice.call(arguments, 0)) : arguments);
|
||||
};
|
||||
}, __slice = Array.prototype.slice;
|
||||
// `nodes.coffee` contains all of the node classes for the syntax tree. Most
|
||||
|
||||
@@ -1,11 +1,8 @@
|
||||
(function(){
|
||||
var BALANCED_PAIRS, EXPRESSION_CLOSE, EXPRESSION_END, EXPRESSION_START, IMPLICIT_BLOCK, IMPLICIT_CALL, IMPLICIT_END, IMPLICIT_FUNC, INVERSES, Rewriter, SINGLE_CLOSERS, SINGLE_LINERS, _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, helpers, include, pair;
|
||||
var __bind = function(func, obj, args) {
|
||||
obj = obj || {};
|
||||
return (typeof args !== 'undefined' && args !== null) ? function() {
|
||||
return func.apply(obj, args.concat(__slice.call(arguments, 0)));
|
||||
} : function() {
|
||||
return func.apply(obj, arguments);
|
||||
return function() {
|
||||
return func.apply(obj || {}, args ? args.concat(__slice.call(arguments, 0)) : arguments);
|
||||
};
|
||||
}, __slice = Array.prototype.slice, __hasProp = Object.prototype.hasOwnProperty;
|
||||
// The CoffeeScript language has a good deal of optional syntax, implicit syntax,
|
||||
|
||||
@@ -16,7 +16,7 @@
|
||||
};
|
||||
utilities.functions = {
|
||||
extend: "function(child, parent) {\n var ctor = function(){ };\n ctor.prototype = parent.prototype;\n child.__superClass__ = parent.prototype;\n child.prototype = new ctor();\n child.prototype.constructor = child;\n}",
|
||||
bind: "function(func, obj, args) {\n obj = obj || {};\n return (typeof args !== 'undefined' && args !== null) ? function() {\n return func.apply(obj, args.concat(" + (utilities.key('slice')) + ".call(arguments, 0)));\n } : function() {\n return func.apply(obj, arguments);\n };\n}",
|
||||
bind: "function(func, obj, args) {\n return function() {\n return func.apply(obj || {}, args ? args.concat(" + (utilities.key('slice')) + ".call(arguments, 0)) : arguments);\n };\n}",
|
||||
range: "function(array, from, to, exclusive) {\n return [\n (from < 0 ? from + array.length : from || 0),\n (to < 0 ? to + array.length : to || array.length) + (exclusive ? 0 : 1)\n ];\n}",
|
||||
hasProp: 'Object.prototype.hasOwnProperty',
|
||||
slice: 'Array.prototype.slice'
|
||||
|
||||
@@ -25,11 +25,8 @@ exports.utilities: class utilities
|
||||
|
||||
bind: """
|
||||
function(func, obj, args) {
|
||||
obj = obj || {};
|
||||
return (typeof args !== 'undefined' && args !== null) ? function() {
|
||||
return func.apply(obj, args.concat(${utilities.key('slice')}.call(arguments, 0)));
|
||||
} : function() {
|
||||
return func.apply(obj, arguments);
|
||||
return function() {
|
||||
return func.apply(obj || {}, args ? args.concat(${utilities.key('slice')}.call(arguments, 0)) : arguments);
|
||||
};
|
||||
}
|
||||
"""
|
||||
|
||||
Reference in New Issue
Block a user