Underscore.js学习

underscore.js是一个JS框架,在原生JavaScript基础上提供了很多有用的工具API。

underscore官网 http://underscorejs.org/
官网中文翻译 http://www.css88.com/doc/underscore/。

直接上代码,我是直接引用js,官网有node初始化版本的。

<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<script src="js/jquery-3.1.1.min.js"></script>
<script src="js/underscore.js"></script>
<script>
$(document).ready(function () {
var arr = [1,2,4,5,4];
//_下划线是underscore的一个对象
//遍历 each
_.each(arr,function(val){
alert(val);
});
//map
_.map(arr,function(val){

});
//last,first
console.log(_.last(arr));
console.log(_.first(arr));
});
</script>
</head>
<body>
</body>
</html>

 

posted @ 2016-12-21 13:50  江洋小盗  阅读(172)  评论(0编辑  收藏  举报