将方法添加到带有prototype
的constrctor函数或者将其放在构造函数函数中,如下面的代码有什么区别?两者都被认为是OOP吗?
//Constructor function
function Box(in) {
this.name = in;
}
// Method for constructor function Box
Box.prototype.showName = function() {
return this.name;
}
或
// Constructor function with method inside
function Circle(in) {
this.something = in;
{
// Method
this.showName = function();
return this.something;
}
}