JavaScript对象中的构造函数JavaScript类/对象可以有构造函数吗?它们是如何被创造出来的?
3 回答
慕姐4208626
TA贡献1852条经验 获得超7个赞
function Box(color) // Constructor{
this.color = color;}Box.prototype.getColor = function(){
return this.color;};function Box(col){
var color = col;
this.getColor = function()
{
return color;
};}var blueBox = new Box("blue");alert(blueBox.getColor()); // will alert bluevar greenBox = new Box("green");alert(greenBox.getColor());
// will alert green添加回答
举报
0/150
提交
取消
