/*  */
/* globals MutationObserver *///全局变化观察者 // can we use __proto__?//我们能用__proto__吗?
var hasProto = '__proto__' in {}; // Browser environment sniffing//浏览器环境嗅探
var inBrowser = typeof window !== 'undefined';//是不是在浏览器中
var UA = inBrowser && window.navigator.userAgent.toLowerCase();
var isIE = UA && /msie|trident/.test(UA);//是不是IE浏览器 内核为trident
var isIE9 = UA && UA.indexOf('msie 9.0') > 0;//是不是IE9
var isEdge = UA && UA.indexOf('edge/') > 0;
var isAndroid = UA && UA.indexOf('android') > 0;
var isIOS = UA && /iphone|ipad|ipod|ios/.test(UA);
var isChrome = UA && /chrome\/\d+/.test(UA) && !isEdge; // this needs to be lazy-evaled because vue may be required before
// vue-server-renderer can set VUE_ENV//这里需要被懒运算,因为vue可能被需要在 vue服务渲染器设置VUE_ENVz之前
var _isServer;
var isServerRendering = function () {
if (_isServer === undefined) {
/* istanbul ignore if */
if (!inBrowser && typeof global !== 'undefined') {
// detect presence of vue-server-renderer and avoid
// Webpack shimming the process
_isServer = global['process'].env.VUE_ENV === 'server';
} else {
_isServer = false;
}
}
return _isServer
}; // detect devtools//探测开发工具
var devtools = inBrowser && window.__VUE_DEVTOOLS_GLOBAL_HOOK__; /* istanbul ignore next */
function isNative (Ctor) {//判断是不是本地的方法
return /native code/.test(Ctor.toString())
} var hasSymbol =
typeof Symbol !== 'undefined' && isNative(Symbol) &&
typeof Reflect !== 'undefined' && isNative(Reflect.ownKeys); /**
* Defer a task to execute it asynchronously.//推迟一个任务异步的执行它
*/
var nextTick = (function () {
var callbacks = [];
var pending = false;
var timerFunc; function nextTickHandler () {
pending = false;
var copies = callbacks.slice(0);
callbacks.length = 0;
for (var i = 0; i < copies.length; i++) {
copies[i]();
}
}
  //the nextTick(下一个标记) behavior(行为) leverages(利用) the microtask queue(微任务队列), which can be accessed(被存取)
// via(经由) either native Promise(要么本机的promise).then or MutationObserver(html5新特性之一Mutation Observer(变动观察器)是监视DOM变动的接口。当DOM对象树发生任何变动时,Mutation Observer会得到通知。).
// MutationObserver has wider support, however it is seriously bugged in//变动观察器具有广泛的支持,然而它被严重的干扰在苹果9.3.3以上系统的网页中,当触摸事件被触发时。
// UIWebView in iOS >= 9.3.3 when triggered in touch event handlers. It
// completely stops working after triggering a few times... so, if native//它完全的停止工作在触发后一段时间,所以如果本地的promise是有效的,我们将会使用promise。
// Promise is available, we will use it:
/* istanbul ignore if */
if (typeof Promise !== 'undefined' && isNative(Promise)) {//如果Promise存在
var p = Promise.resolve();
var logError = function (err) { console.error(err); };//打印错误日志
timerFunc = function () {
p.then(nextTickHandler).catch(logError);
// in problematic UIWebViews, Promise.then doesn't completely break, but//在有问题的网页中,Promise.then 不会完全的销毁,但是它会被卡住在一个不可思议的状态下
// it can get stuck in a weird state where callbacks are pushed into the//这个状态是回调函数被推送到微任务队列,但是队列没有被冲洗,直到浏览器需要做其他工作,举例来说操作一个定时器
// microtask queue but the queue isn't being flushed, until the browser
// needs to do some other work, e.g. handle a timer. Therefore we can//因此我们能推动这个微任务队列去冲洗通过增加一个空的定时器
// "force" the microtask queue to be flushed by adding an empty timer.
if (isIOS) { setTimeout(noop); }
};
} else if (typeof MutationObserver !== 'undefined' && (//判断是否支持“变动观察器”
isNative(MutationObserver) ||
// PhantomJS and iOS 7.x
MutationObserver.toString() === '[object MutationObserverConstructor]'
)) {
// use MutationObserver where native Promise is not available,//在本地Promise无效的情况下使用“变动观察器”
// e.g. PhantomJS IE11, iOS7, Android 4.4
var counter = 1;
var observer = new MutationObserver(nextTickHandler);
var textNode = document.createTextNode(String(counter));
observer.observe(textNode, {
characterData: true
});
timerFunc = function () {
counter = (counter + 1) % 2;
textNode.data = String(counter);
};
} else {
// fallback to setTimeout//后退执行定时器
/* istanbul ignore next */
timerFunc = function () {
setTimeout(nextTickHandler, 0);
};
} return function queueNextTick (cb, ctx) {
var _resolve;
callbacks.push(function () {
if (cb) { cb.call(ctx); }
if (_resolve) { _resolve(ctx); }
});
if (!pending) {
pending = true;
timerFunc();
}
if (!cb && typeof Promise !== 'undefined') {
return new Promise(function (resolve) {
_resolve = resolve;
})
}
}
})();
 

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源码学习分享(八)

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

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

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

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

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

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

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

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

    /** * Check if value is primitive//检查该值是否是个原始值 */ function isPrimitive (value) { return typeof value ...

  9. Vue.js 源码学习笔记

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

随机推荐

  1. virtualvenv+django+uWSGI+nginx 部署

    原创博文 转载请注明出处! 1. virtualvenv 2. django 3. uWSGI 4. nginx 5. 踩坑记录 1. virtualvenv virtualvenv install ...

  2. 【NOIP提高A组模拟2018.8.14】 区间

    区间加:差分数组修改 O(n)扫描,负数位置单调不减 #include<iostream> #include<cstring> #include<cstdio> # ...

  3. LeetCode之Weekly Contest 92

    第一题:转置矩阵 问题: 给定一个矩阵 A, 返回 A 的转置矩阵. 矩阵的转置是指将矩阵的主对角线翻转,交换矩阵的行索引与列索引. 示例 1: 输入:[[1,2,3],[4,5,6],[7,8,9] ...

  4. python入门:CONTINUE 的作用 跳出本次循环后,重新开始循环

    #!/usr/bin/env python # -*- coding:utf-8 -*- # CONTINUE 的作用 跳出本次循环后,重新开始循环 import time while True: ' ...

  5. windows下配置Nginx支持php

    编辑配置文件nginx.conf worker_processes 1; events { worker_connections 1024; } http { include mime.types; ...

  6. 【mysql】【转发】Cannot proceed because system tables used by Event Scheduler were found damaged at server start

    本地:mac 10.12.3  mysql 5.6   远程:linux 7.3    mysql 5.7.18.  (远程数据库yum安装,又5.6升级到5.7)   步骤:从本地数据库导出数据到远 ...

  7. python标准输入输出

    input() 读取键盘输入 input() 函数从标准输入读入一行文本,默认的标准输入是键盘. input 可以接收一个Python表达式作为输入,并将运算结果返回. print()和format( ...

  8. Huawei warns against 'Berlin Wall' in digital world

    From China Daily Huawei technologies criticized recent registration imposed on the Chinese tech comp ...

  9. LeetCode(225) Implement Stack using Queues

    题目 Implement the following operations of a stack using queues. push(x) – Push element x onto stack. ...

  10. 思维水题:UVa512-Spreadsheet Tracking

    Spreadsheet Tracking Data in spreadsheets are stored in cells, which are organized in rows (r) and c ...