zoukankan      html  css  js  c++  java
  • 源码小结

    1. oberver/array.js

    /*
     * not type checking this file because flow doesn't play well with
     * dynamically accessing methods on Array prototype
     */
    
    function def (obj, key, val, enumerable) {
      Object.defineProperty(obj, key, {
        value: val,
        enumerable: !!enumerable,
        writable: true,
        configurable: true
      })
    }
    
    const arrayProto = Array.prototype
    const arrayMethods = Object.create(arrayProto)
    
    const methodsToPatch = [
      'push',
      'pop',
      'shift',
      'unshift',
      'splice',
      'sort',
      'reverse'
    ]
    
    // /**
    //  * Intercept mutating methods and emit events
    //  */
    methodsToPatch.forEach(function (method) {
      // cache original method
      const original = arrayProto[method]
      console.log('methods:', method)
    // 重写数组原生态的方法。 def(arrayMethods, method, function mutator (...args) { const result = original.apply(this, args) console.log('this:=', this) console.log('args=:', args) let inserted switch (method) { case 'push': case 'unshift': inserted = args break case 'splice': inserted = args.slice(2) break } return result }) }) const arrayKeys = Object.getOwnPropertyNames(arrayMethods) var arr1 = [1, 3, 4, 9]
    // 实例对象挂上 arr1.__proto__ = arrayMethods console.log('arr1=', arr1.slice(2))

    core/index.js 

    // 两层意思,1 个Vue.挂个静态成员FunctionalRenderContext
    function Vue () {
    
    }
    function FunctionalRenderContext () {
        console.log('hello world')
    }
    Object.defineProperty(Vue, 'FunctionalRenderContext', {
      value: FunctionalRenderContext
    })
    FunctionalRenderContext.prototype = {
        _o:function () {
            console.log('o is:o')
        },
        _k: function () {
            console.log('k is: k')
        }
    }
    // Vue.FunctionalRenderContext();
    var o = new Vue.FunctionalRenderContext()
    o._o()
  • 相关阅读:
    项目实现多数据库支持 规格严格
    KeyTool 4096 RSA JDK1.5 1.4 规格严格
    KeyTool用法 规格严格
    Tomcat ssl配置 规格严格
    redmine install 规格严格
    zlib1.2.5的编译 规格严格
    Class unload 规格严格
    Ubuntu 8.10 “Intrepid Ibex” 发布时间表确定
    22项Windows或Mac不能而Linux可以的事
    英语谚语
  • 原文地址:https://www.cnblogs.com/liuyinlei/p/11132900.html
Copyright © 2011-2022 走看看