underscore-analysis
underscore-analysis copied to clipboard
【NO LONGER UPDATE】underscore-1.8.3.js 源码解读 & 系列文章(完)
这篇文章并不在我的 underscore 源码解读计划中,直到 @pod4g 同学回复了我的 issue(详见 https://github.com/hanzichi/underscore-analysis/issues/2#issuecomment-227361035)。其实之前也有同学提出 isNaN 有 native 的 function,正好借此文辨析下几个常见的概念、方法,她们是 NaN,Number.NaN,isNaN,Number.isNaN,以及 underscore 中的 _.isNaN,顺便揪出了一个 BUG。 顺便安利,完整的 underscore 源码解读系列文章请戳 https://github.com/hanzichi/underscore-analysis # NaN & Number.NaN ok,首先来了解下 NaN 和 Number.NaN 两个属性。...
# Why underscore 最近开始看 underscore.js 源码,并将 [underscore.js 源码解读](https://github.com/hanzichi/underscore-analysis) 放在了我的 2016 计划中。 阅读一些著名框架类库的源码,就好像和一个个大师对话,你会学到很多。为什么是 underscore?最主要的原因是 underscore 简短精悍(约 1.5k 行),封装了 100 多个有用的方法,耦合度低,非常适合逐个方法阅读,适合楼主这样的 JavaScript 初学者。从中,你不仅可以学到用 void 0 代替 undefined 避免 undefined 被重写等一些小技巧 ,也可以学到变量类型判断、函数节流&函数去抖等常用的方法,还可以学到很多浏览器兼容的 hack,更可以学到作者的整体设计思路以及...
不看不知道,一看吓一跳,已经整整一个月没有更新 underscore 源码解读系列文章了。前面我们已经完成了 Object ,Array,Collection 上的扩展方法的源码剖析,本文开始来解读 Function 上的扩展方法。 完整的 underscore 源码解读系列文章请移步 https://github.com/hanzichi/underscore-analysis,觉得还阔以的话,给个 star 鼓励下楼主呗 ^_^ # bind 简介 Ok,今天要讲的正是 bind。关于 bind,可以先移步楼主以前写的文章 [ECMAScript 5(ES5) 中 bind 方法简介备忘](http://www.cnblogs.com/zichi/p/4357023.html),有个基本的概念。 bind() 方法会创建一个新函数,当这个新函数被调用时,它的 this 值是传递给...
前文 [浅谈 Web 中前后端模板引擎的使用](https://github.com/hanzichi/underscore-analysis/issues/25) 我们简单了解了模板引擎在前后端的应用场景,本文重点深入 Underscore 的模板函数 \_.template,来看看它的用法以及实现原理。 # from simplest 我们从 [官方文档](http://underscorejs.org/#template) 中最简单的例子说起。 ```javascript var compiled = _.template("hello: "); var html = compiled({name: 'moe'}); // hello: moe ``` *{name:...
underscore 源码解读之 function 的扩展方法部分即将进入尾声,我们重点剖析了解了 bind 方法的使用场景以及兼容方式,函数节流、函数去抖,以及 memoize 方法,本文我们来看看 underscore 还为 function 扩展了哪些有用(有意思)的方法。 ## _.delay & _.defer _.delay 能使得函数延迟执行,其实就是封装了一个定时器。 ``` javascript // Delays a function for the given number of milliseconds,...