1、_.noConflict:命名冲突处理方法

_.noConflict = function() {
root._ = previousUnderscore;
   //返回this不错
return this;
};

2、_.identity():默认的迭代处理器

_.identity = function(value) {
return value;
};

3、_.times():调用指定的迭代器n次

_.times = function (n, iterator, context) {
for (var i = 0; i < n; i++) iterator.call(context, i);
};

4、_.escape():转义html代码;_.unescape()与前者相反

_.escape = function(string) {
   //string转为字符串:''+string
return (''+string).replace(/&/g, '&').replace(/</g, '<').replace(/>/g, '>').replace(/"/g, '"').replace(/'/g, ''').replace(/\//g,'/');
};

5、_result():返回对象指定属性的值,如果为函数,则返回执行的值

_.result = function(object, property) {
if (object == null) return null;
var value = object[property];
return _.isFunction(value) ? value.call(object) : value;
};

6、_.mixin():用自己的程序扩展underscore, 

_.mixin = function(obj) {
each(_.functions(obj), function(name){
    //将自定义方法添加到underscore对象中,支持对象式调用;同时加入到_中,支持函数式调用
addToWrapper(name, _[name] = obj[name]);
});
};
_.mixin({
capitalize: function(string) {
return string.charAt(0).toUpperCase() + string.substring(1).toLowerCase();
}
});
_("fabio").capitalize();
=> "Fabio"

7、_.uniqueId():给对象或DOM创建唯一ID

_.uniqueId = function(prefix) {
var id = idCounter++;
return prefix ? prefix + id : id;
};

8、_.templateSettings():定义模板的界定符号

_.templateSettings = {
evaluate : /<%([\s\S]+?)%>/g,
interpolate : /<%=([\s\S]+?)%>/g,
escape : /<%-([\s\S]+?)%>/g
};

9、_.template():比较麻烦

underscore utility的更多相关文章

  1. Singal Page App:使用Knockout和RequireJS创建高度模块化的单页应用引擎

    Singal Page App 开篇扯淡 距离上一篇文章已经有好几个月,也不是没有时间记录点东西,主要是换了新的工作,在一家外资工作,目前的工作内容大多都是前端开发,新接触的东西因为时间原因,大多还不 ...

  2. Underscore.js

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

  3. 新手入门Underscore.js 中文(template)

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

  4. HiShop2.x版本中的上传插件分析,得出所用的模板语言为Underscore.js 1.6.0且自己已修改

    效果: 上传组件非常的酷,但是分析其使用JS写法使用了模板语言的,代码如下: <script type="text/j-template" id="tpl_popb ...

  5. 【跟着子迟品 underscore】Object Functions 相关源码拾遗 & 小结

    Why underscore 最近开始看 underscore.js 源码,并将 underscore.js 源码解读 放在了我的 2016 计划中. 阅读一些著名框架类库的源码,就好像和一个个大师对 ...

  6. 你可能不再需要Underscore

    过去几年像 Underscore 和 lodash 等库进入许多JavaScript程序员的工具函数中.虽然这些工具库可以使你的代码写起来更容易,但是他们不一定使代码更简单或更容易理解. 各种工具函数 ...

  7. Underscore.js 初探

    一. 简介   Underscore 这个单词的意思是“下划线”.   Underscore.js 是一个 JavaScript 工具库,提供了一整套的辅助方法供你使用.   Think that - ...

  8. underscore 笔记

    //reduce是汇总 递归 var perDesc=[ {name: "haha", "email": "haha@email.com"} ...

  9. underscore.js 一个强大的js函数库

    Underscore提供的100多个函数,主要涉及对Collection.Object.Array.Function的操作: Collections(集合) each, map, reduce, re ...

随机推荐

  1. too few PGs per OSD (20 < min 30)

    ceph osd pool set replicapool pg_num 150 ceph osd pool set replicapool pgp_num 150

  2. mysql datetime与timestamp精确到毫秒的问题

    CREATE TABLE `tab1` (`tab1_id` VARCHAR(11) DEFAULT NULL,`create` TIMESTAMP(3) NULL DEFAULT NULL,`cre ...

  3. sql重复数据只取一条记录

    1.SQL SELECT DISTINCT 语句 在表中,可能会包含重复值.这并不成问题,不过,仅仅列出不同(distinct)的值. 关键词 DISTINCT 用于返回唯一不同的值. 语法: SEL ...

  4. RN中关于ListView的使用

    1. ListView dataSource 介绍: ListView需要指定数据的来源.传入数据必须是数组,或者是字典里面嵌套数组 系统会根据你传入的数据自动生成section和row 每一个字典的 ...

  5. grep匹配字符串出现的次数

    背景:想要匹配一个html页面中某个字符出现的次数   遇到的问题: 用grep -c “xxx字符”得到的是行数,如果一行中有多个匹配到的字符,只会算作一个       解决方法: 使用grep - ...

  6. VirtualBox中的虚拟机在Ubuntu 下无法启动之问题解决

    我通过重新安装box解决的.发现,box安装,直接apt install有可能会出现虚拟机无法启动的问题. 一.添加VirtualBox的源并安装5.1版本virtualbox官网:https://w ...

  7. fckeditor 数据库 取值 显示

    用fckeditor把html代码存到数据库中,取出来显示的时候用什么控件呢?用Literal  或  Label  控件.

  8. jquery之DataTables的使用

      jquery之DataTables的使用  document jquery function lsquo 强大的表格解决方案,有多强大,一起来看下吧: 1.DataTables的默认配置 $(do ...

  9. Android 获取ROOT权限原理解析

    一. 概述 本文介绍了android中获取root权限的方法以及原理,让大家对android玩家中常说的“越狱”有一个更深层次的认识. 二. Root的介绍 1.       Root 的目的 可以让 ...

  10. Gitlab不小心关闭了sign-in,无法登录web的坑。。。

    手贱一不小心用root在gitlab后台把登录功能给关了,当时我就懵逼了. 解决方法如下: #进入数据库修改配置[root@gitlab-server ~]# gitlab-psql gitlabhq ...