zoukankan      html  css  js  c++  java
  • vue.js 源代码学习笔记 ----- instance proxy

    /* not type checking this file because flow doesn't play well with Proxy */
    
    import config from 'core/config'
    import { warn, makeMap } from '../util/index'
    
    let initProxy
    
    if (process.env.NODE_ENV !== 'production') {

    //一些能使用的全局变量 const allowedGlobals
    = makeMap( 'Infinity,undefined,NaN,isFinite,isNaN,' + 'parseFloat,parseInt,decodeURI,decodeURIComponent,encodeURI,encodeURIComponent,' + 'Math,Number,Date,Array,Object,Boolean,String,RegExp,Map,Set,JSON,Intl,' + 'require' // for Webpack/Browserify )
    //未定义缺使用了 const warnNonPresent
    = (target, key) => { warn( `Property or method "${key}" is not defined on the instance but ` + `referenced during render. Make sure to declare reactive data ` + `properties in the data option.`, target ) }
    //es6 proxy详解 const hasProxy
    = typeof Proxy !== 'undefined' && Proxy.toString().match(/native code/) if (hasProxy) { const isBuiltInModifier = makeMap('stop,prevent,self,ctrl,shift,alt,meta')
    //避免设置 系统鼠标 属性
       config.keyCodes
    = new Proxy(config.keyCodes, { set (target, key, value) { if (isBuiltInModifier(key)) { warn(`Avoid overwriting built-in modifier in config.keyCodes: .${key}`) return false } else { target[key] = value return true } } }) } const hasHandler = { has (target, key) { const has = key in target const isAllowed = allowedGlobals(key) || key.charAt(0) === '_' if (!has && !isAllowed) { warnNonPresent(target, key) }
    //如果有这个key 或者 不是全局函数, 返回true
    return has || !isAllowed } } const getHandler = { get (target, key) { if (typeof key === 'string' && !(key in target)) { warnNonPresent(target, key) } return target[key] } } initProxy = function initProxy (vm) { if (hasProxy) { // determine which proxy handler to use const options = vm.$options const handlers = options.render && options.render._withStripped ? getHandler : hasHandler vm._renderProxy = new Proxy(vm, handlers) } else { vm._renderProxy = vm } } } export { initProxy }

     此方法做了一些对象操作的拦截 和 警告

  • 相关阅读:
    记一次跳转
    html2canvas在生成图片过程中遇到的坑vue
    数组对象push新的元素,导致其他新复制的数据也发生改变,不是一一对应改变(深拷贝和浅拷贝)
    js生成的新结构点击事件不生效
    箭头函数和普通函数的区别
    vue (vue-cli主要写构建工具的使用)
    favicon.ico可能会遇到的的坑
    video不能在个别浏览器不能播放
    a标签的拨打电话、发邮件、QQ发消息,另外控件分享转发
    git使用的简单命令
  • 原文地址:https://www.cnblogs.com/dhsz/p/7116410.html
Copyright © 2011-2022 走看看