ClassName *object = new ClassName(param);
Foo foo = new Foo();
function DOG(name){ this.name = name; }
var dogA = new DOG('大毛'); alert(dogA.name); // 大毛
function DOG(name){ this.name = name; this.species = '犬科'; }
var dogA = new DOG('大毛'); var dogB = new DOG('二毛');
dogA.species = '猫科'; alert(dogB.species); // 显示"犬科",不受dogA的影响
function DOG(name){ this.name = name; } DOG.prototype = { species : '犬科' }; var dogA = new DOG('大毛'); var dogB = new DOG('二毛'); alert(dogA.species); // 犬科 alert(dogB.species); // 犬科
DOG.prototype.species = '猫科'; alert(dogA.species); // 猫科 alert(dogB.species); // 猫科
您需要 登录 才可以下载或查看,没有帐号?立即注册
举报
本版积分规则 发表回复 回帖后跳转到最后一页
1314学习网 ( 浙ICP备10214163号 )
GMT+8, 2025-5-3 09:37
Powered by Discuz! X3.4
© 2001-2013 Comsenz Inc.