方法内外同名处理
element中,renderCell
外部可以传递renderCell方法,内部重写该方法,核心就是变量只是存储引用的值,重新赋值就是改了变量保存的地址,并不会删除或者失效之前指向的内容,只是改了当前指向而已,可以用中间变量存储之前的引用,否则将会遗失相关内容,vue中的render也有做类似的操作
// 配置// template<template><el-table-column :renderCell="renderCell"></el-table-column></template>// jsmethods: {renderCell (h) {return (<span>外部renderCell</span>)}}// 内部处理let originRenderCell = column.renderCell; // originRenderCell暂存外部方法引用地址// renderCell引用修改指向新方法column.renderCell = function () {if (...) {const children = originRenderCell()}}
vue中的处理,需要把mount作为用户友好的api暴露出来,但是内部也需要这么友好的命名,且需要再次包装带有编译器的入口
// 备份mount方法// 包装一层$mount方法const mount = Vue.prototype.$mountVue.prototype.$mount = function (el?: string | Element,hydrating?: boolean): Component {return mount.call(this, el, hydrating)}
