摘要:
Returnstrueifvariableisundefined.如果变量没有被定义1 _.isUndefined(window.missingVariable);2 => true源码:1 _.isUndefined = function(obj) {2 return obj === void 0;3 }; 阅读全文
摘要:
Returnstrueif the value ofobjectisnull返回true,如果值是null对象1 _.isNull(null);2 => true3 _.isNull(undefined);4 => false源码:1 _.isNull = function(obj) {2 return obj === null;3 }; 阅读全文
摘要:
ReturnstrueifobjectisNaN.Note: this is not the same as the nativeisNaNfunction, which will also return true if the variable isundefined.返回true如果对象是NaN, 原生函数isNaN.undefined类型也将返回true。这里将返回false1 _.isNaN(NaN);2 => true3 isNaN(undefined);4 => true5 _.isNaN(undefined);6 => false源码: _.isNaN = fu 阅读全文
摘要:
Returnstrueifobjectis a RegExp.返回true,如果是一个正则表达式1 _.isRegExp(/moe/);2 => true源码:1 _.isRegExp = function(obj) {2 return toString.call(obj) == '[object RegExp]';3 }; 阅读全文
摘要:
Returnstrueifobjectis a Date.如果对象是一个日期类型1 _.isDate(new Date());2 => true源码:1 _.isDate = function(obj) {2 return toString.call(obj) == '[object Date]';3 }; 阅读全文
摘要:
Returnstrueifobjectis eithertrueorfalse返回true,如果对象是bool类型1 _.isBoolean(null);2 => false源码:1 _.isBoolean = function(obj) {2 return obj === true || obj === false || toString.call(obj) == '[object Boolean]';3 }; 阅读全文
摘要:
Returnstrueifobjectis a finite Number.返回true如果对象是一个有限的数目1 _.isFinite(-101);2 => true3 4 _.isFinite(-Infinity);5 => false源码:1 _.isFinite = function(obj) {2 return _.isNumber(obj) && isFinite(obj);3 }; 阅读全文
摘要:
Returnstrueifobjectis a Number (includingNaN).返回true,如果是数字类型,包括NAN1 _.isNumber = function(obj) {2 return toString.call(obj) == '[object Number]';3 };源码:1 _.isNumber = function(obj) {2 return toString.call(obj) == '[object Number]';3 }; 阅读全文
摘要:
Returnstrueifobjectis a String返回true,如果是字符串1 _.isString("moe");2 => true源码1 _.isString = function(obj) {2 return toString.call(obj) == '[object String]';3 }; 阅读全文
摘要:
Returnstrueifobjectis a Function返回true.如果是一个方法1 _.isFunction(alert);2 => true源码:1 _.isFunction = function(obj) {2 return toString.call(obj) == '[object Function]';3 }; 阅读全文
摘要:
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 阅读全文
摘要:
Returnstrueifvalueis an Object.返回true,如果值是一个对象1 _.isObject({});2 => true3 _.isObject(1);4 => false源码:1 _.isObject = function(obj) {2 return obj === Object(obj);3 }; 阅读全文
摘要:
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 }; 阅读全文
摘要:
Returnstrueifobjectis a DOM element.返回true如果对象是DOM元素1 .isElement(jQuery('body')[0]);2 => true源码:1 _.isElement = function(obj) {2 return !!(obj && obj.nodeType == 1);3 }; 阅读全文
摘要:
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... 阅读全文
摘要:
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 阅读全文
摘要:
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 阅读全文
摘要:
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 阅读全文
摘要:
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 阅读全文
摘要:
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", 阅读全文