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

2019-03-03 21:34

function(/*anything*/ it){ // summary: Return true if it is an Array. 判断输入的类型是否为数组 Usage Example:

dojo.lang.isArray({a:1,b:2}); //will return false dojo.lang.isArray([1,2,3]); //will return true dojo.lang.isArrayLike

function(/*anything*/ it){ // summary:

//Return true if it can be used as an array (i.e. is an object with //an integer length property). dojo.lang.isFunction

function(/*anything*/ it){ // summary: Return true if it is a Function. 判断输入的类型是否为函数 Usage Example:

dojo.lang.isFunction(function() {}); //will return true dojo.lang.isString

判断输入的类型是否为字符串 function(/*anything*/ it){ // summary: Return true if it is a String. Usage Example:

dojo.lang.isString(\dojo.lang.isString(0); //will return false dojo.lang.isAlien

判断输入的类型是否为系统函数 function(/*anything*/ it){

// summary: Return true if it is not a built-in function. False if not. Usage Example:

dojo.lang.isAlien(isNaN); //will return true dojo.lang.isBoolean

判断输入的类型是否为布尔类型 function(/*anything*/ it){ // summary: Return true if it is a Boolean. Usage Example:

dojo.lang.isBoolean(2>1); //will return true 下面的 is***()函数有点不安全 dojo.lang.isNumber

判断输入的类型是否为数值,根据注释所说,此函数使用不太可靠,但是可替换使用的系统函数 isNaN 也 不太可靠 // summary: Return true if it is a number. // description: //

WARNING - In most cases, isNaN(it) is sufficient to determine whether or not

// something is a number or can be used as such. For example, a number or string // can be used interchangably when accessing array items (array[\// array[1]) and isNaN will return false for both values (\// isNumber(\

// Also, isNumber(NaN) returns true, again, this isn't general y useful, but there // are corner cases (like when you want to make sure that two things are really // the same type of thing). That is really where isNumber \//

// Recommendation - Use isNaN(it) when possible dojo.lang.isUndefined

判断输入是否为未定义,根据注释所说,此函数有可能会导致抛出异常,推荐使 用 typeof foo == \来判断

// summary: Return true if it is not defined. // description: //

WARNING - In some cases, isUndefined will not behave as you

// might expect. If you do isUndefined(foo) and there is no earlier // reference to foo, an error will be thrown before isUndefined is // called. It behaves correctly if you scope yor object first, i.e. // isUndefined(foo.bar) where foo is an object and bar isn't a // //

propertyof the object.

// Recommendation - Use typeof foo == \模块:dojo.lang.array 处理数组相关 api dojo.lang.has

判断对象是否具有指定属性,不过这个方法有用吗,不如直接使用 if(name in obj) function(/*Object*/obj, /*String*/name)

// summary: is there a property with the passed name in obj? Usage Example:

dojo.lang.has(dojo.lang, \dojo.lang.isEmpty

判断对象或数组是否为空 function(/*Object*/obj) // summary: // // // // // //

can be used to determine 求出 if the passed object is \the case of array-like objects, the length, property is

examined 检查, but for other types of objects iteration 重复 is used to examine the iterable \

non-prototypal properties have been assigned 分配. This iteration is prototype-extension safe. Usage Example:

dojo.lang.isEmpty({a: 1}); //will return false dojo.lang.isEmpty([]); //will return true dojo.lang.map

调用指定的方法处理指定的数组或字符串

function(/*Array*/arr, /*Object|Function*/obj, /*Function?*/unary_func) // summary: // // // // // //

returns a new array constituded from the return values of

passing each element of arr into unary_func. The obj parameter may be passed to enable the passed function to be called in that scope. In environments that support JavaScript 1.6, this function is a passthrough to the built-in map() function provided by Array instances. For details on this, see:

// http://developer.mozilla.org/en/docs/Core_JavaScript_1.5_Reference:Global_Objects:Array:map // examples:

//dojo.lang.map([1, 2, 3, 4], function(item){ return item+1 }); // returns [2, 3, 4, 5] Usage Example:

dojo.lang.map([1,2,3,4,5], function(x) { return x * x;}); //will return [1,4,9,16,25] dojo.lang.reduce

function(/*Array*/arr, initialValue, /*Object|Function*/obj, /*Function*/binary_func) // summary: // // // // // // // // // //

similar to Python's builtin reduce() function. The result of the previous 前面的 computation 计算 is passed as the first argument 争论 to binary_func along with the next value from arr. The result of this call is used along with the subsequent 后来的 value from arr, and this continues until arr is exhausted. The return value is the last result. The \safely omitted and the order of obj and binary_func may be

reversed. The default order of the obj and binary_func argument will probably be reversed in a future release, and this call order is supported today. // examples: // //

dojo.lang.reduce([1, 2, 3, 4], function(last, next){ return last+next}); returns 10

dojo.lang.forEach

遍历指定的数组或字符串,并对其中的元素调用指定的方法

function(/*Array*/anArray, /*Function*/callback, /*Object?*/thisObject) // summary: //

for every item in anArray, call callback with that item as its // // //

only parameter. Return values are ignored 忽略. This funciton corresponds 协调(and wraps) the JavaScript 1.6 forEach method. For more details, see:

//http://developer.mozilla.org/en/docs/Core_JavaScript_1.5_Reference:Global_Objects:Array:forEach Usage Example:

dojo.lang.forEach(\dojo.lang.every

检查指定的数组是否全部满足指定方法的条件

function(/*Array*/arr, /*Function*/callback, /*Object?*/thisObject) // summary: // // // // // //

determines 决定 whether or not every item in the array satisfies 符合 the condition 条件 implemented by callback. thisObject may be used to

scope the call to callback. The function signature 特征 is derived 起源 from the JavaScript 1.6 Array.every() function. More information on this can be found here:

http://developer.mozilla.org/en/docs/Core_JavaScript_1.5_Reference:Global_Objects:Array:every // examples:

// // // //

dojo.lang.every([1, 2, 3, 4], function(item){ return item>1; }); // returns false

dojo.lang.every([1, 2, 3, 4], function(item){ return item>0; }); // returns true Usage Example:

dojo.lang.every([1,-2,3], function(x) { return x > 0; }); //指定的数组不是全大于 0 的,因此返回 false dojo.lang.some

检查指定的数组是否部分满足指定方法的条件

function(/*Array*/arr, /*Function*/callback, /*Object?*/thisObject) // summary: // //

determines whether or not any item in the array satisfies the

condition 条件 implemented by callback. thisObject may be used to // // // //

scope the call to callback. The function signature is derived from the JavaScript 1.6 Array.some() function. More information on this can be found here:

http://developer.mozilla.org/en/docs/Core_JavaScript_1.5_Reference:Global_Objects:Array:some // examples: // // // //

dojo.lang.some([1, 2, 3, 4], function(item){ return item>1; }); // returns true

dojo.lang.some([1, 2, 3, 4], function(item){ return item<1; }); // returns false Usage Example:

dojo.lang.some([1,-2,3], function(x) { return x > 0; }); //指定的数组有大于 0 的元素,因此返回 true dojo.lang.filter

根据指定的方法来过滤指定的数组

function(/*Array*/arr, /*Function*/callback, /*Object?*/thisObject) // summary: // // // // // //

returns a new Array with those items from arr that match the condition implemented by callback.thisObject may be used to scope the call to callback. The function signature is derived from the JavaScript 1.6 Array.filter() function, although

special accomidation is made in our implementation for strings. More information on the JS 1.6 API can be found here:

//http://developer.mozilla.org/en/docs/Core_JavaScript_1.5_Reference:Global_Objects:Array:filter // examples: //

dojo.lang.some([1, 2, 3, 4], function(item){ return item>1; }); // returns [2, 3, 4] Usage Example:

dojo.lang.filter([1,-2,3], function(x) { return x > 0; }); //will return [1, 3] dojo.lang.unnest

把指定的参数或数组转换为一维数组 function(/* ... */){ // summary: // //

// usage: // //

Creates a 1-D array out of all the arguments passed, unravelling any array-like objects in the process unnest(1, 2, 3) ==> [1, 2, 3]

unnest(1, [2, [3], [[[4]]]]) ==> [1, 2, 3, 4] Usage Example:

dojo.lang.unnest(1, 2, 3); //will return [1, 2, 3]

dojo.lang.unnest(1, [2, [3], [[[4]]]]); //will return [1, 2, 3, 4] dojo.lang.toArray 将输入转换为数组

function(/*Object*/arrayLike, /*Number*/startOffset){ // summary: // //

Converts an array-like object (i.e. arguments, DOMCollection) to an array. Returns a new Array object. Usage Example: function test() {

return dojo.lang.toArray(arguments, 1); }

test(1,2,3,4,5); //will return [2,3,4,5] 模块:dojo.lang.extras dojo.lang.setTimeout

延迟指定时间后执行指定方法

function(/*Function*/func, /*int*/delay /*, ...*/){ // summary: //

Sets a timeout in milliseconds to execute a function in a given //

// usage: // //

context with optional arguments.

dojo.lang.setTimeout(Object context, function func, number delay[, arg1[, ...]]); dojo.lang.setTimeout(function func, number delay[, arg1[, ...]]); Usage Example:

function onTime(msg){dojo.debug(msg)}dojo.lang.setTimeout(onTime, 1000, \秒后会输出调试 信息\秒后会输出调试信息\dojo.lang.clearTimeout function(/*int*/timer){

// summary: clears timer by number from the execution queue 排列 // FIXME: // // //

why do we have this function? It's not portable outside of browser environments and it's a stupid wrapper on something that browsers provide anyway.

dojo.lang.getNameInObj


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

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

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

马上注册会员

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