DOJO-API中文参考手册附加注解实例(4)

2019-03-03 21:34

获得指定项目在指定对象中的名称

function(/*Object*/ns, /*unknown*/item) // summary: // //

looks for a value in the object ns with a value matching item and returns the property name

// ns: if null, dj_global is used // item: value to return a name for Usage Example:

dojo.lang.getNameInObj(dojo, dojo.debug); //will return \dojo.lang.shallowCopy

返回指定对象的浅表复制副本

function(/*Object*/obj, /*Boolean?*/deep) // summary: //

copies object obj one level deep, or full depth if deep is true Usage Example:

dojo.lang.shallowCopy({}); //will return a 空对象 dojo.lang.firstValued 返回第一个非定义的参数 function(/* ... */){

// summary: Return the first argument that isn't undefined Usage Example:

var a;dojo.lang.firstValued(a,2,3); //will return 2 dojo.lang.getObjPathValue

function(/*String*/objpath, /*Object?*/context, /*Boolean?*/create){ // summary: // //

Gets a value from a reference specified as a string descriptor, (e.g. \

// context: if not specified, dj_global is used

// create: if true, undefined objects in the path are created. dojo.lang.setObjPathValue

function(/*String*/objpath, /*anything*/value, /*Object?*/context, /*Boolean?*/create) // summary: // // // //

Sets a value on a reference specified as a string descriptor. (e.g. \assignment, except that the object structure in question can optionally be created if it does not exist. // context: if not specified, dj_global is used // create: if true, undefined objects in the path are created. // FIXME: why is this function valuable? It should be scheduled for

// removal on the grounds that dojo.parseObjPath does most of it's work and // is more straightforward and has fewer dependencies. Also, the order of // arguments is bone-headed. \// *sigh*

模块:dojo.lang.func dojo.lang.hitch

将指定的方法挂在指定的对象下并返回该方法

function(/*Object*/thisObject, /*Function|String*/method /*, ...*/) // summary: // //

//

Returns a function that will only ever execute in the a given scope (thisObject). This allows for easy use of object member functions in callbacks and other places in which the \// // // // //

otherwise not reference the expected scope. Any number of default positional arguments may be passed as parameters beyond \Each of these values will be used to \for the hitched function. Note that the order of arguments may be reversed in a future version.

// thisObject: the scope to run the method in // method: // //

// usage: // //

a function to be \thisObject to be used as the basis for the binding

dojo.lang.hitch(foo, \

dojo.lang.hitch(foo, myFunction); // returns a function that runs myFunction in the scope of foo Usage Example:

func = {test: function(s) {alert(s)}};

dojo.lang.mixin(func, {demo: dojo.lang.hitch(func, \ func.demo(\dojo.lang.nameAnonFunc

function(/*Function*/anonFuncPtr, /*Object*/thisObj, /*Boolean*/searchForNames){ // summary: // // // // // //

Creates a reference to anonFuncPtr in thisObj with a completely unique name. The new name is returned as a String. If searchForNames is true, an effort will be made to locate an

existing reference to anonFuncPtr in thisObj, and if one is found, the existing name will be returned instead. The default is for searchForNames to be false. dojo.lang.forward

返回自身对象的指定名称的方法引用 function(funcName){ // summary: // // //

Returns a function that forwards a method call to this.funcName(...). Unlike dojo.lang.hitch(), the \not fixed on a single object. Ported from Mochi Usage Example:

func = {test: function(s) {alert(s)}, demo: dojo.lang.forward(\ func.demo(\dojo.lang.curry

What is curry? 请参阅这篇文章:http://www.svendtofte.com/code/curried_javas cript/

function(thisObj, func /* args ... */) // summary: // // // // // // // // //

similar to the curry() method found in many functional programming environments, this function returns an \

function, bound to a particular scope, and \number of arguments. The curry method is unique in that it returns a function that may return other \called repeatedly. New functions are returned until the arity of the original function is reached, at which point the underlying function (func) is called in the scope thisObj with all of the accumulated arguments (plus any extras) in positional order. // examples: // // // // // // // // // // // // // // // // // // //

assuming a function defined like this: var foo = {

bar: function(arg1, arg2, arg3){ dojo.debug.apply(dojo, arguments); } };

dojo.lang.curry() can be used most simply in this way:

tmp = dojo.lang.curry(foo, foo.bar, \tmp(\

// debugs: \tmp(\

// debugs: \tmp();

// returns a function exactly like tmp that expects one argument other intermittent functions could be created until the 3 positional arguments are filled: // // //

// // // // // // // // // // // //

tmp = dojo.lang.curry(foo, foo.bar, \tmp2 = tmp(\tmp2(\

// debugs: \tmp2(\

// debugs: \

curry() can also be used to call the function if enough arguments are passed in the initial invocation:

dojo.lang.curry(foo, foo.bar, \// debugs: \

dojo.lang.curry(foo, foo.bar, \// debugs: \

// FIXME: the order of func and thisObj should be changed!!! Usage Example:

function add(a, b) {

return a + b; }

dojo.lang.curry(null, add, 2, 3); //will return 5 dojo.lang.curry(null, add, 2)(3); //will return 5 dojo.lang.curry(null, add)(2)(3); //will return 5 dojo.lang.curry(null, add)()(2)(3); //will return 5 dojo.lang.curryArguments

与 dojo.lang.curry 类似,但是可以选择忽略掉前 n 个参数

function(/*Object*/thisObj, /*Function*/func, /*Array*/args, /*Integer, optional*/offset) // summary: // // // //

similar to dojo.lang.curry(), except that a list of arguments to start the curry with may be provided as an array instead of as positional arguments. An offset may be specified from the 0 index to skip some elements in args. Usage Example:

function add(a, b) {

return a + b; }

dojo.lang.curryArguments(null, add, [1,2,3,4,5], 2); //will return 7 (= 3 + 4) dojo.lang.tryThese

测试参数指定所有函数,并返回第一个返回值不为 0 的函数值,没看懂这个函数哪里用得着 function(/*...*/){ // summary: // // //

executes each function argument in turn, returning the return value from the first one which does not throw an exception in execution. Any number of functions may be passed. from seno:

dojo.lang.tryThese 方法和 prototype 中的 Try.these()方法是一样的,

xmlNode.text 在一些浏览器中好用,但是 xmlNode.textContent 在另一些浏览器中正常工作。 Try.these()方法我们可以得到正常工作的那个方法的返回值。

DOJO-API中文参考手册附加注解实例(4).doc 将本文的Word文档下载到电脑 下载失败或者文档不完整,请联系客服人员解决!

下一篇:国际物流历年试题

相关阅读
本类排行
× 注册会员免费下载(下载后可以自由复制和排版)

马上注册会员

注:下载文档有可能“只有目录或者内容不全”等情况,请下载之前注意辨别,如果您已付费且无法下载或内容有问题,请联系我们协助你处理。
微信: QQ: