源码小结

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()

 

转载于:https://www.cnblogs.com/liuyinlei/p/11132900.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值