Javascript 对象 / 类
Javascript Object / Classes
以下两种不同类型的区别 Javascript 类.
第一个:
var apple = new function() {
this.type = "macintosh";
this.color = "red";
this.getInfo = function () {
return this.color + ' ' + this.type + ' apple';
};
}
第二个一:
var apple = ({
type:'macintosh',
color:'red',
getInfo: function() {
return type +' '+ color + 'apple';
}
});
两者都在.js文件中定义
提前致谢
第一个是 class 您可以从中创建对象
var test = new apple();
第二个是您可以使用其成员和方法的对象
以下两种不同类型的区别 Javascript 类.
第一个:
var apple = new function() {
this.type = "macintosh";
this.color = "red";
this.getInfo = function () {
return this.color + ' ' + this.type + ' apple';
};
}
第二个一:
var apple = ({
type:'macintosh',
color:'red',
getInfo: function() {
return type +' '+ color + 'apple';
}
});
两者都在.js文件中定义 提前致谢
第一个是 class 您可以从中创建对象
var test = new apple();
第二个是您可以使用其成员和方法的对象