/**
* 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. OC和C++的区别

    C++语言特点: 1.在C语言的基础上进行扩充和完善,使C++兼容了C语言的面向过程特点,又成为了一种面向对象的程序设计语言: 2.可以使用抽象数据类型进行基于对象的编程: 3.可以使用多继承.多态进 ...

  2. JS数据结构与算法--单向链表

    链表结构:链表中每个元素由一个存储元素本身的节点和一个指向下一元素的引用组成.如下所示(手画的,比较丑,懒得用工具画了,嘻嘻) 1.append方法,向链表末尾插入一个节点 2.insert(posi ...

  3. Spinal Tap Case -freecodecamp算法题目

    Spinal Tap Case 1.要求 将字符串转换为 spinal case. Spinal case 是 all-lowercase-words-joined-by-dashes 这种形式的,也 ...

  4. python入门:BREAK 的用法 跳当前循环后,不再执行下面代码块

    #!/urs/bin/env python # -*- coding:utf-8 -*- # BREAK 的作用 跳当前循环后,不再执行下面代码块 while True: ') break ') #w ...

  5. python入门:输出1-10的所有数

    #!/usr/bin/env python # -*- coding:utf-8 -*- #输出1-10的所有数 """ 变量kaishi的赋值为数字1,while 真, ...

  6. destoon手机端mobileurl函数增加城市分类参数

    mobileurl函数在include/global.func.php 858行 共四个参数,moduleid-模型id,catid-分类id,itemid -文章id,page-页码 functio ...

  7. 如何编写自己的C语言头文件

    一些初学C语言的人,不知道头文件(*.h文件)原来还可以自己写的.只知道调用系统库函数时,要使用#include语句将某些头文件包含进去.其实,头文件跟.C文件一样,是可以自己写的.头文件是一种文本文 ...

  8. java web项目(spring项目)中集成webservice ,实现对外开放接口

    什么是WebService?webService小示例 点此了解 下面进入正题: Javaweb项目(spring项目)中集成webservice ,实现对外开放接口步骤: 准备: 采用与spring ...

  9. Linux交换分区swap

    一.SWAP 说明 1.1 SWAP 概述 当系统的物理内存不够用的时候,就需要将物理内存中的一部分空间释放出来,以供当前运行的程序使用.那些被释放的空间可能来自一些很长时间没有什么操作的程序,这些被 ...

  10. OpenSSL version mismatch. Built against 1000105f, you have 10001060

    http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=732940 http://ftp.debian.org/debian/pool/main/o/ope ...