/**
* 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源码学习分享(二)的更多相关文章

  1. vue.js源码学习分享(一)

    今天看了vue.js源码  发现非常不错,想一边看一遍写博客和大家分享 /** * Convert a value to a string that is actually rendered. *转换 ...

  2. vue.js源码学习分享(九)

    /* */ var arrayKeys = Object.getOwnPropertyNames(arrayMethods);//获取arrayMethods的属性名称 /** * By defaul ...

  3. vue.js源码学习分享(七)

    var _Set; /* istanbul ignore if */ if (typeof Set !== 'undefined' && isNative(Set)) { // use ...

  4. vue.js源码学习分享(六)

    /* */ /* globals MutationObserver *///全局变化观察者 // can we use __proto__?//我们能用__proto__吗? var hasProto ...

  5. vue.js源码学习分享(八)

    /* */ var uid$1 = 0; /** * A dep is an observable that can have multiple * directives subscribing() ...

  6. vue.js源码学习分享(五)

    //配置项var config = { /** * Option merge strategies (used in core/util/options)//选项合并策略 */ optionMerge ...

  7. vue.js源码学习分享(四)

    /** * Generate a static keys string from compiler modules.//从编译器生成一个静态键字符串模块. */ function genStaticK ...

  8. vue.js源码学习分享(三)

    /** * Mix properties into target object.//把多个属性插入目标的对象 */ function extend (to, _from) { for (var key ...

  9. Vue.js 源码学习笔记

    最近饶有兴致的又把最新版 Vue.js 的源码学习了一下,觉得真心不错,个人觉得 Vue.js 的代码非常之优雅而且精辟,作者本身可能无 (bu) 意 (xie) 提及这些.那么,就让我来吧:) 程序 ...

随机推荐

  1. SpringBoot(一)_Eclipse的安装和使用

    1.Eclipse中安装STS插件: Help -> Eclipse Marketplace… Search或选择“Popular”标签,选择Spring Tool Suite (STS) fo ...

  2. 禅与 Objective-C 编程艺术(Zen and the Art of the Objective-C Craftsmanship)

    英文版Zen and the Art of the Objective-C Craftsmanshiphttps://github.com/objc-zen/objc-zen-book 中文版禅与 O ...

  3. iOS深拷贝与浅拷贝

    概念 对象拷贝有两种方式:浅复制和深复制.顾名思义,浅复制,并不拷贝对象本身,仅仅是拷贝指向对象的指针:深复制是直接拷贝整个对象内存到另一块内存中. 如图详解:

  4. 【转】Qt Socket简单通信

    最近要用到Qt的Socket部分,网上关于这部分的资料都比较复杂,我在这总结一下,把Socket的主要部分提取出来,实现TCP和UDP的简单通信. 1.UDP通信 UDP没有特定的server端和cl ...

  5. C++函数的默认参数补充

    1.函数定义时指定默认参数 在C++中,定义函数时可以给形参指定一个默认的值,这样调用函数时如果没有给这个形参赋值(没有对应的实参),那么就使用这个默认的值.也就是说,调用函数时可以省略有默认值的参数 ...

  6. python入门:1-99所有数的和的等式

    #!/usr/bin/env python # -*- coding:utf-8 -*- #1-99所有数的和的等式 #start(开始,译音:思达二测)sum(合计,译音:桑木)temp(临时雇员, ...

  7. 使用TensorFlow的卷积神经网络识别手写数字(2)-训练篇

    import numpy as np import tensorflow as tf import matplotlib import matplotlib.pyplot as plt import ...

  8. ACM-ICPC 2018 徐州赛区网络预赛 H. Ryuji doesn't want to study

    262144K   Ryuji is not a good student, and he doesn't want to study. But there are n books he should ...

  9. Nordic Collegiate Programming Contest 2015​ G. Goblin Garden Guards

    In an unprecedented turn of events, goblins recently launched an invasion against the Nedewsian city ...

  10. Nordic Collegiate Programming Contest 2015​ D. Disastrous Downtime

    You're investigating what happened when one of your computer systems recently broke down. So far you ...