keys_.keys(object) 

Retrieve all the names of the object's properties.

_.keys({one: 1, two: 2, three: 3});
=> ["one", "two", "three"]

values_.values(object) 

Return all of the values of the object's properties.

_.values({one: 1, two: 2, three: 3});
=> [1, 2, 3]

pairs_.pairs(object) 

Convert an object into a list of [key, value] pairs.

_.pairs({one: 1, two: 2, three: 3});
=> [["one", 1], ["two", 2], ["three", 3]]

invert_.invert(object) 

Returns a copy of the object where the keys have become the values and the values the keys. For this to work, all of your object's values should be unique and string serializable.

_.invert({Moe: "Moses", Larry: "Louis", Curly: "Jerome"});
=> {Moses: "Moe", Louis: "Larry", Jerome: "Curly"};

functions_.functions(object) Alias: methods 

Returns a sorted list of the names of every method in an object — that is to say, the name of every function property of the object.

_.functions(_);
=> ["all", "any", "bind", "bindAll", "clone", "compact", "compose" ...

extend_.extend(destination,
*sources)
 

Copy all of the properties in the source objects over to the destination object, and return the destination object. It's in-order, so the last source will override properties of the same name in previous arguments.

_.extend({name: 'moe'}, {age: 50});
=> {name: 'moe', age: 50}

说明:extend函数是直接改动destination參数的,通过以下代码非常easy证明

var destination = {name: 'moe'};
var source = {age: 50}
_.extend(destination, source);
console.log("extend="+destination.age);//50

pick_.pick(object,
*keys)
 

Return a copy of the object, filtered to only have values for the whitelisted(白名单) keys (or array of valid keys). Alternatively accepts a predicate indicating which keys to pick.

_.pick({name: 'moe', age: 50, userid: 'moe1'}, 'name', 'age');
=> {name: 'moe', age: 50}
_.pick({name: 'moe', age: 50, userid: 'moe1'}, function(value, key, object) {
return _.isNumber(value);
});
=> {age: 50}

omit_.omit(object,
*keys)
 

Return a copy of the object, filtered to omit the blacklisted(黑名单) keys (or array of keys). Alternatively accepts a predicate indicating which keys to omit.

_.omit({name: 'moe', age: 50, userid: 'moe1'}, 'userid');
=> {name: 'moe', age: 50}
_.omit({name: 'moe', age: 50, userid: 'moe1'}, function(value, key, object) {
return _.isNumber(value);
});
=> {name: 'moe', userid: 'moe1'}

defaults_.defaults(object,
*defaults)
 

Fill in undefined properties in object with the
first value present in the following list ofdefaults objects.

var iceCream = {flavor: "chocolate"};
_.defaults(iceCream, {flavor: "vanilla", sprinkles: "lots"});
=> {flavor: "chocolate", sprinkles: "lots"}

说明:这个函数和extend非常类似,假设destination和source中属性名没有反复,那么2个函数的功能是全然一致的。

区别在于:当属性名有同名的时候,extend直接用source中的值覆盖掉destination中的值;而defaults则会依据destination中的属性值是否为undefined区别对待。

var iceCream = {flavor: "chocolate",sprinkles:undefined};
_.defaults(iceCream, {flavor: "vanilla", sprinkles: "lots"});
console.log("iceCream=" + iceCream.flavor);//chocolate
console.log("sprinkles=" + iceCream.sprinkles);//lots

clone_.clone(object) 

Create a shallow-copied(浅拷贝) clone of the object. Any nested objects or arrays will be copied by reference, not duplicated.

_.clone({name: 'moe'});
=> {name: 'moe'};

tap_.tap(object,
interceptor)
 

Invokes interceptor with the object, and then returns object. The primary purpose of this method is to "tap into" a method chain, in order to perform operations on intermediate results within the chain.

_.chain([1,2,3,200])
.filter(function(num) { return num % 2 == 0; })
.tap(alert)
.map(function(num) { return num * num })
.value();
=> // [2, 200] (alerted)
=> [4, 40000]

has_.has(object,
key)
 

Does the object contain the given key? Identical to object.hasOwnProperty(key),
but uses a safe reference to the hasOwnProperty function, in
case it's been overridden accidentally.

_.has({a: 1, b: 2, c: 3}, "b");
=> true

property_.property(key) 

Returns a function that will itself return the key property of
any passed-in object.

var moe = {name: 'moe'};
'moe' === _.property('name')(moe);
=> true

matches_.matches(attrs) 

Returns a predicate function that will tell you if a passed in object contains all of the key/value properties present in attrs.

var ready = _.matches({selected: true, visible: true});
var readyToGoList = _.filter(list, ready);

isEqual_.isEqual(object,
other)
 

Performs an optimized deep comparison between the two objects, to determine if they should be considered equal.

var moe   = {name: 'moe', luckyNumbers: [13, 27, 34]};
var clone = {name: 'moe', luckyNumbers: [13, 27, 34]};
moe == clone;
=> false
_.isEqual(moe, clone);
=> true

isEmpty_.isEmpty(object) 

Returns true if an enumerable object contains no values (no enumerable own-properties). For strings and array-like objects _.isEmpty checks
if the length property is 0.

_.isEmpty([1, 2, 3]);
=> false
_.isEmpty({});
=> true

isElement_.isElement(object) 

Returns true if object is a DOM element.

_.isElement(jQuery('body')[0]);
=> true

isArray_.isArray(object) 

Returns true if object is an Array.

(function(){ return _.isArray(arguments); })();
=> false
_.isArray([1,2,3]);
=> true

isObject_.isObject(value) 

Returns true if value is an Object. Note that JavaScript arrays and functions are objects, while (normal) strings and numbers are not.

_.isObject({});
=> true
_.isObject(1);
=> false

isArguments_.isArguments(object) 

Returns true if object is an Arguments object.

(function(){ return _.isArguments(arguments); })(1, 2, 3);
=> true
_.isArguments([1,2,3]);
=> false

isFunction_.isFunction(object) 

Returns true if object is a Function.

_.isFunction(alert);
=> true

isString_.isString(object) 

Returns true if object is a String.

_.isString("moe");
=> true

isNumber_.isNumber(object) 

Returns true if object is a Number (including NaN).

_.isNumber(8.4 * 5);
=> true

isFinite_.isFinite(object) 

Returns true if object is a finite Number.

_.isFinite(-101);
=> true _.isFinite(-Infinity);
=> false

isBoolean_.isBoolean(object) 

Returns true if object is either true or false.

_.isBoolean(null);
=> false

isDate_.isDate(object) 

Returns true if object is a Date.

_.isDate(new Date());
=> true

isRegExp_.isRegExp(object) 

Returns true if object is a RegExp.

_.isRegExp(/moe/);
=> true

isNaN_.isNaN(object) 

Returns true if object is NaN.

Note: this is not the same as the native isNaN function, which will also return true for many other not-number values, such as undefined.

_.isNaN(NaN);
=> true
isNaN(undefined);
=> true
_.isNaN(undefined);
=> false

isNull_.isNull(object) 

Returns true if the value of object is null.

_.isNull(null);
=> true
_.isNull(undefined);
=> false

isUndefined_.isUndefined(value) 

Returns true if value is undefined.

_.isUndefined(window.missingVariable);
=> true

(三)underscore.js框架Objects类API学习的更多相关文章

  1. underscore.js框架使用

    Underscore.js是一个很精干的库,压缩后只有4KB.它提供了几十种函数式编程的方法,弥补了标准库的不足,大大方便了JavaScript的编程.MVC框架Backbone.js就将这个库作为自 ...

  2. Java数据持久层框架 MyBatis之API学习三(XML 映射配置文件)

    对于MyBatis的学习而言,最好去MyBatis的官方文档:http://www.mybatis.org/mybatis-3/zh/index.html 对于语言的学习而言,马上上手去编程,多多练习 ...

  3. Java数据持久层框架 MyBatis之API学习八(Java API详解)

    对于MyBatis的学习而言,最好去MyBatis的官方文档:http://www.mybatis.org/mybatis-3/zh/index.html 对于语言的学习而言,马上上手去编程,多多练习 ...

  4. Java数据持久层框架 MyBatis之API学习四(xml配置文件详解)

    摘录网址: http://blog.csdn.net/u010107350/article/details/51292500 对于MyBatis的学习而言,最好去MyBatis的官方文档:http:/ ...

  5. Java数据持久层框架 MyBatis之API学习十(Logging详解)

    对于MyBatis的学习而言,最好去MyBatis的官方文档:http://www.mybatis.org/mybatis-3/zh/index.html 对于语言的学习而言,马上上手去编程,多多练习 ...

  6. Java数据持久层框架 MyBatis之API学习六(Mapper XML 文件详解)

    对于MyBatis的学习而言,最好去MyBatis的官方文档:http://www.mybatis.org/mybatis-3/zh/index.html 对于语言的学习而言,马上上手去编程,多多练习 ...

  7. Java数据持久层框架 MyBatis之API学习九(SQL语句构建器详解)

    对于MyBatis的学习而言,最好去MyBatis的官方文档:http://www.mybatis.org/mybatis-3/zh/index.html 对于语言的学习而言,马上上手去编程,多多练习 ...

  8. Java数据持久层框架 MyBatis之API学习七(动态 SQL详解)

    对于MyBatis的学习而言,最好去MyBatis的官方文档:http://www.mybatis.org/mybatis-3/zh/index.html 对于语言的学习而言,马上上手去编程,多多练习 ...

  9. Java数据持久层框架 MyBatis之API学习二(入门)

    对于MyBatis的学习而言,最好去MyBatis的官方文档:http://www.mybatis.org/mybatis-3/zh/index.html 对于语言的学习而言,马上上手去编程,多多练习 ...

随机推荐

  1. siege压力测试工具安装和介绍

    Siege是linux下的一个web系统的压力测试工具,支持多链接,支持get和post请求,可以对web系统进行多并发下持续请求的压力测试. 安装 Siege #wget http://www.jo ...

  2. 场景/故事/story——寻物者发布消息场景、寻失主发布消息场景、消息展示场景、登录网站场景

    1.背景:(1)典型用户:吴昭[主要]  尤迅[次要] 王丛[次要] 佑豪[次要](2)用户的需求/迫切需要解决的问题a.吴昭:经常在校园各个地方各个时间段,丢失物品需要寻找.b.吴昭:偶尔浏览一下最 ...

  3. Hive| 查询

    Hive中执行SQL语句时,出现类似于“Display all 469 possibilities? (y or n)”的错误,根本原因是因为SQL语句中存在tab键导致,tab键在linux系统中是 ...

  4. day56 文件 文档处理,事件

    前情回顾: 1. 前情回顾 0. 选择器补充 - 属性选择器 - $("[egon]") - $("[type='text']") - $("inpu ...

  5. radio按钮单选效果

    必须有name,并且是同一值,判断效果可用value值确定

  6. 使用sparksql往kafka推送数据

    一.相关配置参数 1.同级目录resource文件夹下配置 brokers_list=kafkaxxx02broker01:9092,kafkaxxx02broker02:9092,kafkaxxx0 ...

  7. NIO缓冲区基本操作:rewind(),clear(),flip()

    rewind() rewind()方法将position置0,清除mark,它的作用在于为提取Buffer的有效数据做准备. ByteBuffer byteBuf = ByteBuffer.alloc ...

  8. vim编辑

    vim 重点在于光标的移动,模式的切换,删除,查找,替换,复制,黏贴,撤销命令的使用 vim的三种模式:命令模式(打开文件默认进入此模式)编辑模式(输入模式)末行模式(按:键进入,只能从命令模式下按键 ...

  9. VirtualBox 共享文件夹设置及使用方法

    工具:VirtualBox,ubuntu14.04 1.选择要设置共享文件夹的虚拟机,点击设置 点击共享文件夹,新建文件夹,选择路径 2.打开虚拟机,从上方工具栏中找到设备,然后点击安装增强功能(由于 ...

  10. 南阳219----An problem about date

    /* 1600年一月一日为星期6,所以算出ymd与1600-1-1差多少天对7取余即可 */ #include<stdio.h> ]={}; int main() { ,ans; ; i& ...