vue.js源码学习分享(二)
/**
* Check if value is primitive//检查该值是否是个原始值
*/
function isPrimitive (value) {
return typeof value === 'string' || typeof value === 'number'
} /**
* Create a cached version of a pure function.//创建一个纯粹的函数的缓存版本
*/
function cached (fn) {
var cache = Object.create(null);//创建一个缓存对象
return (function cachedFn (str) {//返回一个函数
var hit = cache[str];//以函数的参数为键
return hit || (cache[str] = fn(str))//如果缓存对象中存在这个键,那么就从缓存中返回这个函数,如果没有就把这个函数赋值到缓存对象中并且返回
})
} /**
* Camelize a hyphen-delimited string.//驼峰化一个连字符连接的字符串
*/
var camelizeRE = /-(\w)/g;
var camelize = cached(function (str) {
return str.replace(camelizeRE, function (_, c) { return c ? c.toUpperCase() : ''; })
}); /**
* Capitalize a string.//对一个字符串首字母大写
*/
var capitalize = cached(function (str) {
return str.charAt(0).toUpperCase() + str.slice(1)//把第一个字符串的首个字符大写,把除第一个字符的字符串返回与大写的首字符拼接
}); /**
* Hyphenate a camelCase string.用字符号连接一个驼峰的字符串
*/
var hyphenateRE = /([^-])([A-Z])/g;
var hyphenate = cached(function (str) {
return str
.replace(hyphenateRE, '$1-$2')//$1为正则表达式匹配的第一个元素$2为第二个元素
.replace(hyphenateRE, '$1-$2')
.toLowerCase()//使之最小化
}); /**
* Simple bind, faster than native//简单的绑定,会比原生的更快
*/
function bind (fn, ctx) {
function boundFn (a) {
var l = arguments.length;//获取实参的数量
return l
? l > 1//如果实参数量大于1
? fn.apply(ctx, arguments)
: fn.call(ctx, a)//实参数量等于1
: fn.call(ctx)//没有参数
}
// record original fn length//记录一下原始的形参数量
boundFn._length = fn.length;
return boundFn
} /**
* Convert an Array-like object to a real Array.//转换一个类数组的对象为真正的数组
*/
function toArray (list, start) {
start = start || 0;//如果start存在则用start如果不存在则用0;
var i = list.length - start;//设置新数组的数量
var ret = new Array(i);//新建数组
while (i--) {5
ret[i] = list[i + start];
}
return ret
}
vue.js源码学习分享(二)的更多相关文章
- vue.js源码学习分享(一)
今天看了vue.js源码 发现非常不错,想一边看一遍写博客和大家分享 /** * Convert a value to a string that is actually rendered. *转换 ...
- vue.js源码学习分享(九)
/* */ var arrayKeys = Object.getOwnPropertyNames(arrayMethods);//获取arrayMethods的属性名称 /** * By defaul ...
- vue.js源码学习分享(七)
var _Set; /* istanbul ignore if */ if (typeof Set !== 'undefined' && isNative(Set)) { // use ...
- vue.js源码学习分享(六)
/* */ /* globals MutationObserver *///全局变化观察者 // can we use __proto__?//我们能用__proto__吗? var hasProto ...
- vue.js源码学习分享(八)
/* */ var uid$1 = 0; /** * A dep is an observable that can have multiple * directives subscribing() ...
- vue.js源码学习分享(五)
//配置项var config = { /** * Option merge strategies (used in core/util/options)//选项合并策略 */ optionMerge ...
- vue.js源码学习分享(四)
/** * Generate a static keys string from compiler modules.//从编译器生成一个静态键字符串模块. */ function genStaticK ...
- vue.js源码学习分享(三)
/** * Mix properties into target object.//把多个属性插入目标的对象 */ function extend (to, _from) { for (var key ...
- Vue.js 源码学习笔记
最近饶有兴致的又把最新版 Vue.js 的源码学习了一下,觉得真心不错,个人觉得 Vue.js 的代码非常之优雅而且精辟,作者本身可能无 (bu) 意 (xie) 提及这些.那么,就让我来吧:) 程序 ...
随机推荐
- Apache超时配置
Apache超时配置 1. KeepAliveTimeout 语法 KeepAliveTimeout seconds 默认 5 上下文 server config, virtual host 说明 服 ...
- Angular-constructor和ngOnInit区别
参考文档:https://blog.csdn.net/u010730126/article/details/64486997 总结:constructor做依赖注入,避免业务操作: ngOninit做 ...
- Codeforces Round #513 (rated, Div. 1 + Div. 2)
前记 眼看他起高楼:眼看他宴宾客:眼看他楼坍了. 比赛历程 开考前一分钟还在慌里慌张地订正上午考试题目. “诶这个数位dp哪里见了鬼了???”瞥了眼时间,无奈而迅速地关去所有其他窗口,临时打了一个缺省 ...
- strace用法
strace -- trace system calls and signals strace是Linux环境下的一款程序调试工具,用来监察一个应用程序所使用的系统调用及它所接收的系统信 ...
- 拼接Python字符串最常见的六种方式
最常见的六种方式拼接Python字符串 字符串是所有编程语言中都有的基本变量的类型,程序员基本每天都在和字符串打交道. 每种字符串拼接方式的使用场景各不相同,我们可以在开发过程中灵活运用. 一.用逗号 ...
- ubuntu gcc的下载链接,比较快的。
http://mirrors.163.com/ubuntu-releases/ http://xhmikosr.1f0.de/tools/msys/
- CentOS7.2下Hadoop2.7.2的集群搭建
1.基本环境: 操作系统: Centos 7.2.1511 三台虚机: 192.168.163.224 master 192.168.163.225 node1 192.168.163.226 ...
- 使用Blend的一些问题和技巧
WPF开发,界面处理首选Blend,如果你开发了两年WPF都没接触过blend(当然这种几率不高),或者你刚接触WPF,可以考虑使用Blend,这货也算得上一个神器,上手也不难.以下有两位讲得不错,大 ...
- 小x的质数(线性O(n)筛素数)
小x的质数 题目描述 小 X 是一位热爱数学的男孩子,在茫茫的数字中,他对质数更有一种独特的情感.小 X 认为,质数是一切自然数起源的地方. 在小 X 的认知里,质数是除了本身和 11 以外,没有其他 ...
- luogu1501 [国家集训队]Tree II
lct裸题 #include <iostream> #include <cstdio> using namespace std; typedef long long ll; i ...