码迷,mamicode.com
首页 > 其他好文 > 详细

underscore utility

时间:2015-08-17 21:24:05      阅读:127      评论:0      收藏:0      [点我收藏+]

标签:

_.noConflict

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

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

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

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

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

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

_.mixin = function(obj) {
    each(_.functions(obj), function(name){
    //将自定义方法添加到underscore对象中,支持对象式调用;同时加入到_中,支持函数式调用 addToWrapper(name, _[name] = obj[name]); }); };

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

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

_.template():比较麻烦

underscore utility

标签:

原文地址:http://www.cnblogs.com/wang-jing/p/4737612.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!