1 /* See license.txt for terms of usage */ 2 3 define([ 4 "firebug/lib/trace", 5 ], 6 function(FBTrace) { 7 "use strict"; 8 9 // ********************************************************************************************* // 10 // Constants 11 12 /** 13 * @name Func 14 * @lib Utility for Functions 15 */ 16 var Func = {}; 17 18 // ********************************************************************************************* // 19 20 21 /** 22 * Creates a new function that, when called, uses the provided <code>this</code> value 23 * and appends the provided arguments. Note that it differs from Function.prototype.bind which 24 * prepends the provided arguments (that is why this function is called bindRight). 25 * 26 * @param {function} fn The function to bind 27 * @param {*} thisObject The object to pass as the <code>this</code> value 28 * @param {*} ...args the series of parameters to pass to the new function 29 * 30 * @return {function} the new function 31 */ 32 Func.bindRight = function(fn, thisObject/*, ...origArgs*/) 33 { 34 var origArgs = Array.prototype.slice.call(arguments, 2); 35 return function(/*...additionalArgs*/) 36 { 37 var additionalArgs = Array.prototype.slice.call(arguments); 38 return fn.apply(thisObject, additionalArgs.concat(origArgs)); 39 }; 40 } 41 42 // xxxFlorent: TODO: [REST] 43 /** 44 * Creates a new function that, when called, uses the provided <code>this</code> value and arguments. 45 * At the contrary of <code>Function.prototype.bind</code>, any parameter provided at the call is 46 * ignored. 47 * 48 * @param {function} fn The function to bind 49 * @param {*} thisObject The object to pass as the `this` value 50 * @param {*} ...args the series of parameters to pass to the new function 51 * 52 * @return {function} the new Function 53 */ 54 Func.bindFixed = function(fn, thisObject/*, ...args*/) 55 { 56 var args = Array.prototype.slice.call(arguments, 2); 57 return function() { return fn.apply(thisObject, args); }; 58 } 59 60 61 // ********************************************************************************************* // 62 63 Object.freeze(Func); 64 Object.seal(Func); 65 66 return Func; 67 68 // ********************************************************************************************* // 69 }); 70