用JS用面向对象实现一个JS对象。对象里有两个属性,一个方法

2024-10-30 17:24:47
有1个网友回答
网友(1):

function MyObject(){
this.name = "myObject";
this.type = "class";
this.methodA = function(){
alert(this.name);
}
this.methodB = function(){
return this.type;
}
}
var myObject = new MyObject();
myObject.methodA();
var type = myObject.methodB();
alert(type);