相关疑难解决方法(0)

通过原型对象或构造函数设置方法,区别?

你能解释一下构造函数中的设置方法和原型对象之间的区别吗?下面的代码显示设置方法的这两种方式- say_hello而且say_bye都很好地工作:

function MessageClass() {
  this.say_bye = function() { alert('see ya'); };
}

MessageClass.prototype.say_hello = function() { alert('hello'); };

x = new MessageClass();
x.say_hello();
x.say_bye();
Run Code Online (Sandbox Code Playgroud)

javascript constructor prototype

18
推荐指数
3
解决办法
4224
查看次数

标签 统计

constructor ×1

javascript ×1

prototype ×1