随笔分类 - underscore.js
underscore.js _.include [Collections]
摘要:Returnstrueif thevalueis present in thelist, using===to test equality. UsesindexOfinternally, iflistis an Array.检测值是否在列表中出现过,如果出现返回true1 _.include([1, 2, 3], 3);2 => true源码:1 _.include = _.contains = function(obj, target) {2 var found = false;3 if (obj == null) return found;4 if (native...
阅读全文
underscore.js _.pluck[Collections]
摘要:A convenient version of what is perhaps the most common use-case formap: extracting a list of property values.很方便的为你提供一个获取列表值的方法1 var stooges = [{name : 'moe', age : 40}, {name : 'larry', age : 50}, {name : 'curly', age : 60}];2 _.pluck(stooges, 'name');3 => ["
阅读全文
underscore.js _.any[Collections]
摘要:Returnstrueif any of the values in thelistpass theiteratortruth test. Short-circuits and stops traversing the list if a true element is found. Delegates to the native methodsome, if present.如果列表中有一个真正的实体值出现,那么将返回true,别名some1 _.any([null, 0, 'yes', false]);2 => true源码: var any = _.some = _
阅读全文
underscore.js _size[Collections]
摘要:Return the number of values in thelist.返回元素列表的长度1 _.size({one : 1, two : 2, three : 3});2 => 3源码:1 _.size = function(obj) {2 return _.isArray(obj) ? obj.length : _.keys(obj).length;3 };
阅读全文
underscore.js _.map[Collections]
摘要:Produces a new array of values by mapping each value inlistthrough a transformation function (iterator). If the nativemapmethod exists, it will be used instead. Iflistis a JavaScript object,iterator's arguments will be(value, key, list).所有的javascript对象元素都将经过回调函数作用1 _.map([1, 2, 3], function(num)
阅读全文
underscore.js _.each[Collections]
摘要:Iterates over alistof elements, yielding each in turn to aniteratorfunction. Theiteratoris bound to thecontextobject, if one is passed. Each invocation ofiteratoris called with three arguments:(element, index, list). Iflistis a JavaScript object,iterator's arguments will be(value, key, list). De
阅读全文
underscore.js _isUndefined[Object]
摘要:Returnstrueifvariableisundefined.如果变量没有被定义1 _.isUndefined(window.missingVariable);2 => true源码:1 _.isUndefined = function(obj) {2 return obj === void 0;3 };
阅读全文
underscore.js _.isNull[Object]
摘要:Returnstrueif the value ofobjectisnull返回true,如果值是null对象1 _.isNull(null);2 => true3 _.isNull(undefined);4 => false源码:1 _.isNull = function(obj) {2 return obj === null;3 };
阅读全文
underscore.js _.isNaN[Object]
摘要: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
阅读全文
underscore.js _.isRegExp[Object]
摘要:Returnstrueifobjectis a RegExp.返回true,如果是一个正则表达式1 _.isRegExp(/moe/);2 => true源码:1 _.isRegExp = function(obj) {2 return toString.call(obj) == '[object RegExp]';3 };
阅读全文
underscore.js _.isDate[Object]
摘要:Returnstrueifobjectis a Date.如果对象是一个日期类型1 _.isDate(new Date());2 => true源码:1 _.isDate = function(obj) {2 return toString.call(obj) == '[object Date]';3 };
阅读全文
underscore.js_.isBoolean[Object]
摘要: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 };
阅读全文
underscore.js _.finite[Object]
摘要: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 };
阅读全文
underscore.js _.isNumber[Object]
摘要: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 };
阅读全文
underscore.js _.isString[Object]
摘要:Returnstrueifobjectis a String返回true,如果是字符串1 _.isString("moe");2 => true源码1 _.isString = function(obj) {2 return toString.call(obj) == '[object String]';3 };
阅读全文
underscore.js _isFunction[Object]
摘要:Returnstrueifobjectis a Function返回true.如果是一个方法1 _.isFunction(alert);2 => true源码:1 _.isFunction = function(obj) {2 return toString.call(obj) == '[object Function]';3 };
阅读全文
underscore.js _.isArguments[Object]
摘要: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
阅读全文
underscore.js _.isObject[Object]
摘要:Returnstrueifvalueis an Object.返回true,如果值是一个对象1 _.isObject({});2 => true3 _.isObject(1);4 => false源码:1 _.isObject = function(obj) {2 return obj === Object(obj);3 };
阅读全文
underscore.js _.isArray(Object)
摘要: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 };
阅读全文
underscore.js _.isElement(Object)
摘要:Returnstrueifobjectis a DOM element.返回true如果对象是DOM元素1 .isElement(jQuery('body')[0]);2 => true源码:1 _.isElement = function(obj) {2 return !!(obj && obj.nodeType == 1);3 };
阅读全文
浙公网安备 33010602011771号