当搞乱构造函数时,我注意到特权方法被编写为函数表达式,前置this工作正常,而函数声明返回一个Type Error,其中function declaration is not a function。
我知道我们可以通过内部使用thisie 公开来自对象实例的函数:this.functionName
var Foo = function(){
var _color= "blue";
this.getColor = function(){
return _color;
}
function setColor(newColor){
this._color = newColor;
}}var bar = new Foo();console.log(bar.setColor('red'));关于function setColor导致日志输出的函数声明的幕后发生了Uncaught TypeError: bar.setColor is not a function什么?是否提升/声明其作用域的范围是否与此有关
慕村9548890
三国纷争
慕娘9325324
随时随地看视频慕课网APP
相关分类