源码中的两个函数
function generate(
ast,
options
) {
var state = new CodegenState(options);
var code = ast ? genElement(ast, state) : '_c("div")';
return {
render: ("with(this){return " + code + "}"),
staticRenderFns: state.staticRenderFns
}
}
function genStatic(el, state) {
el.staticProcessed = true;
state.staticRenderFns.push(("with(this){return " + (genElement(el, state)) + "}"));
return ("_m(" + (state.staticRenderFns.length - 1) + (el.staticInFor ? ',true' : '') + ")")
}
在vm.$options.render中
function() {
with(this){return _c("div")}
}
Vue.prototype._c
, 仅仅是为了省略this
吗,with
不是存在性能问题么,而且严格模式也不支持。
首先,严格模式下源码的写法依然可以正常执行,然后是官方解释: