2012年4月16日
摘要: Returnstrueifobjectis an Arguments object返回true,如果是arguments对象1 (function(){ return _.isArguments(arguments); })(1, 2, 3);2 => true3 _.isArguments([1,2,3]);4 => false源码:1 _.isArguments = function(obj) {2 return toString.call(obj) == '[object Arguments]';3 };4 if (!_.isArguments(argumen 阅读全文
posted @ 2012-04-16 23:10 himanhimao 阅读(204) 评论(0) 推荐(0) 编辑
摘要: Returnstrueifvalueis an Object.返回true,如果值是一个对象1 _.isObject({});2 => true3 _.isObject(1);4 => false源码:1 _.isObject = function(obj) {2 return obj === Object(obj);3 }; 阅读全文
posted @ 2012-04-16 23:05 himanhimao 阅读(339) 评论(0) 推荐(0) 编辑
摘要: Returnstrueifobjectis an Array.返回true。如果对象是一个数组.1 (function(){ return _.isArray(arguments); })();2 => false3 _.isArray([1,2,3]);4 => true源码:1 _.isArray = nativeIsArray || function(obj) {2 return toString.call(obj) == '[object Array]';3 }; 阅读全文
posted @ 2012-04-16 23:01 himanhimao 阅读(239) 评论(0) 推荐(0) 编辑
摘要: Returnstrueifobjectis a DOM element.返回true如果对象是DOM元素1 .isElement(jQuery('body')[0]);2 => true源码:1 _.isElement = function(obj) {2 return !!(obj && obj.nodeType == 1);3 }; 阅读全文
posted @ 2012-04-16 22:59 himanhimao 阅读(266) 评论(0) 推荐(0) 编辑
摘要: Returnstrueifobjectcontains no values.用于检测一个对象是否是空的1 _.isEmpty([1, 2, 3]);2 => false3 _.isEmpty({});4 => true源码:1 _.isEmpty = function(obj) {2 if (obj == null) return true;3 if (_.isArray(obj) || _.isString(obj)) return obj.length === 0;4 for (var key in obj) if (_.has(obj, key)) retur... 阅读全文
posted @ 2012-04-16 22:56 himanhimao 阅读(1447) 评论(0) 推荐(0) 编辑
摘要: Performs an optimized deep comparison between the two objects, to determine if they should be considered equal.用于比较两个对象的值是否相当,而不是内存引用位置.1 var moe = {name : 'moe', luckyNumbers : [13, 27, 34]};2 var clone = {name : 'moe', luckyNumbers : [13, 27, 34]};3 moe == clone;4 => false5 _.is 阅读全文
posted @ 2012-04-16 22:52 himanhimao 阅读(616) 评论(0) 推荐(0) 编辑
摘要: Does the object contain the given key? Identical toobject.hasOwnProperty(key), but uses a safe reference to thehasOwnPropertyfunction, in case it's been功能等同于object.hasOwnProperty(key),用于检测对象是否存在该属性.1 _.has({a: 1, b: 2, c: 3}, "b");2 => true源码:1 _.has = function(obj, key) {2 return h 阅读全文
posted @ 2012-04-16 22:43 himanhimao 阅读(192) 评论(0) 推荐(0) 编辑
摘要: Invokesinterceptorwith theobject, and then returnsobject. The primary purpose of this method is to "tap into" a method chain, in order to perform operations on intermediate results within the chain对象的拦截器,用于在对象方法链中,调试对象1 _.chain([1,2,3,200])2 .filter(function(num) { return num % 2 == 0; })3 阅读全文
posted @ 2012-04-16 22:33 himanhimao 阅读(205) 评论(0) 推荐(0) 编辑
摘要: Create a shallow-copied clone of theobject. Any nested objects or arrays will be copied by reference, not duplicated.创建对象的浅拷贝克隆.如果是值类型,则拷贝值;如果是引用类型,则拷贝引用地址。1 _.clone({name : 'moe'});2 => {name : 'moe'};源码:1 _.clone = function(obj) {2 if (!_.isObject(obj)) return obj;3 return _.isA 阅读全文
posted @ 2012-04-16 22:14 himanhimao 阅读(462) 评论(0) 推荐(0) 编辑
摘要: Fill in missing properties inobjectwith default values from thedefaultsobjects, and return theobject. As soon as the property is filled, further defaults will have no effect.将默认属性和值填充给对象。再次填充将没有效果1 var iceCream = {flavor : "chocolate"};2 _.defaults(iceCream, {flavor : "vanilla", 阅读全文
posted @ 2012-04-16 21:58 himanhimao 阅读(471) 评论(0) 推荐(0) 编辑