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) 提及这些.那么,就让我来吧:) 程序 ...
随机推荐
- C#算术运算符
一.C#算术运算符 C#语言的算术运算符主要用于数学计算中. 二.示例 using System;using System.Collections.Generic;using System.Linq; ...
- cocos2dx for android 接入 fmod的过程
cocos2dx自带的音效播放有SimpleAudioEngine和AudioEngine两个,SimpleAudioEngine可以播放简单的音效, 如果播放音效数量过多的话,多导致有些音效播放失败 ...
- python入门:if、elif、else 条件语句的基本用法
#!/usr/bin/env python # -*- coding:utf-8 -*- #elif(否则如果,译音:埃尔夫)eise(否则,译音:埃尔斯) #if.elif.else 条件语句的基本 ...
- 拼接Python字符串最常见的六种方式
最常见的六种方式拼接Python字符串 字符串是所有编程语言中都有的基本变量的类型,程序员基本每天都在和字符串打交道. 每种字符串拼接方式的使用场景各不相同,我们可以在开发过程中灵活运用. 一.用逗号 ...
- Hessian知识学习总结(二)——Hessian的helloworld
一.下载Hessian 可在hessian官网http://hessian.caucho.com/ 或者http://download.csdn.net/detail/wodediqizhang/95 ...
- pyecharts用法,本人亲测,陆续更新
主题 除了默认的白色底色和dark之外,还支持安装扩展包 pip install echarts-themes-pypkg echarts-themes-pypkg 提供了 vintage, maca ...
- ProC第三弹
一.前言 我们上面已经了解Windows和Linux下的ProC开发环境,这里我们更进一步去简要介绍下ProC的预编译参数. 二.什么是预编译 预编译过程中,Pro*C/C++会自动生成C或者C++的 ...
- Report Server multiple value 多值选择
一.项目需求 今天在做项目的时候,有一个需求,具体如下:在Report Server中存在一个报表,报表中有一个参数doctor_name,该参数允许多值,默认全部.但是由于前端页面医生选择时多选没有 ...
- Python Cdn平台文件md5验证
第一步 先用脚本实现基本的md5验证 1.python如何实现文件的下载 方法一: 使用 urllib 模块提供的 urlretrieve() 函数.urlretrieve() 方法直接将远程数据下载 ...
- 使用spyder3调试python程序
Ctrl+F5 以Debug模式运行文件 在debug之前记得用%reset 指令清空一下ipython工作空间中的变量,以免影响debug中变量值的查看 无论你是否打断点,都会在第一行语句执行之前中 ...