Editing y.bind This edit will create a new revision. Your details (optional) Name Email (won’t be displayed; might be used for Gravatar) URL Test case details Title * Published (uncheck if you want to fiddle around before making the page public) Description (in case you feel further explanation is needed)(Markdown syntax is allowed) https://github.com/yui/yui3/pull/320 Are you a spammer? (just answer the question) Preparation code Preparation code HTML (this will be inserted in the <body> of a valid HTML5 document in standards mode) (useful when testing DOM operations or including libraries) <script src="http://yui.yahooapis.com/3.9.0pr1/yui/yui-min.js"></script> Include JavaScript libraries as follows: <script src="//cdn.ext/library.js"></script> Define setup for all tests (variables, functions, arrays or other objects that will be used in the tests) (runs before each clocked test loop, outside of the timed code region) (e.g. define local test variables, reset global variables, clear canvas, etc.) (see FAQ) var Y = YUI(), L = Y.Lang, noop = function() {}, Ybind = function(f, c) { var xargs = arguments.length > 2 ? Y.Array(arguments, 2, true) : null; return function() { var fn = L.isString(f) ? c[f] : f, args = (xargs) ? xargs.concat(Y.Array(arguments, 0, true)) : arguments; return fn.apply(c || fn, args); }; }; function bind_(r,f,c){ var xargs = arguments.length > 3 ? Y.Array(arguments, 3, true) : [], Noop = function () { }, bound = function () { var fn = L.isString(f) ? c[f] : f, inArgs = Y.Array(arguments, 0, true); return fn.apply(this instanceof Noop ? this : c, (r ? inArgs.concat(xargs) : xargs.concat(inArgs))); }; if (L.isFunction(f)) { Noop.prototype = f.prototype; bound.prototype = new Noop(); } return bound; }; var newYbind = bind_(0, bind_, null, 0); var slice = Array.prototype.slice; var bind2 = function (method, obj) { var args = arguments.length > 2 ? slice.call(arguments, 2) : [], Noop = function () {}, fBound = function () { var fn = typeof method === 'string' ? obj[method] : method; return fn.apply( this instanceof Noop ? this : obj, args.concat(slice.call(arguments)) ); }; if (typeof method === 'function') { Noop.prototype = method.prototype; fBound.prototype = new Noop(); } return fBound; }; Define teardown for all tests (runs after each clocked test loop, outside of the timed code region) (see FAQ) Code snippets to compare Test 1 Title Async (check if this is an asynchronous test) Code var fn = Ybind(noop, window, 1, 2, 3, 4); Test 2 Title Async (check if this is an asynchronous test) Code var fn = newYbind(noop, window, 1, 2, 3, 4); Test 3 Title Async (check if this is an asynchronous test) Code var fn = bind2(noop, window, 1, 2, 3, 4);