/* Copyright (c) 2004-2006, The Dojo Foundation All Rights Reserved. Licensed under the Academic Free License version 2.1 or above OR the modified BSD license. For more information on Dojo licensing, see: http://dojotoolkit.org/community/licensing.shtml */ dojo.provide("dojo.lang.func"); dojo.require("dojo.lang.common"); /** * Runs a function in a given scope (thisObject), can * also be used to preserve scope. * * hitch(foo, "bar"); // runs foo.bar() in the scope of foo * hitch(foo, myFunction); // runs myFunction in the scope of foo */ dojo.lang.hitch = function(thisObject, method) { if(dojo.lang.isString(method)) { var fcn = thisObject[method]; } else { var fcn = method; } return function() { return fcn.apply(thisObject, arguments); } } dojo.lang.anonCtr = 0; dojo.lang.anon = {}; dojo.lang.nameAnonFunc = function(anonFuncPtr, namespaceObj, searchForNames){ var nso = (namespaceObj || dojo.lang.anon); if( (searchForNames) || ((dj_global["djConfig"])&&(djConfig["slowAnonFuncLookups"] == true)) ){ for(var x in nso){ if(nso[x] === anonFuncPtr){ return x; } } } var ret = "__"+dojo.lang.anonCtr++; while(typeof nso[ret] != "undefined"){ ret = "__"+dojo.lang.anonCtr++; } nso[ret] = anonFuncPtr; return ret; } dojo.lang.forward = function(funcName){ // Returns a function that forwards a method call to this.func(...) return function(){ return this[funcName].apply(this, arguments); }; } dojo.lang.curry = function(ns, func /* args ... */){ var outerArgs = []; ns = ns||dj_global; if(dojo.lang.isString(func)){ func = ns[func]; } for(var x=2; x