這裏是我的問題的的jsfiddle:http://jsfiddle.net/4wyvv/1/JavaScript對象原型屬性訪問
基本上是:
//constructor function
function Maker(){
var str;
this.init = function(str){
this.str = str;
};
this.msg = function(){
return this.str;
};
}
//object from Maker
var obj = new Maker();
obj.init("Hi my name is Dan");
//make sure everything exists and has worked as expected
Audit.Log(obj.msg());
//look in Maker.prototype for the constructor property
Audit.Log(obj.constructor);
//look in Maker.prototype for the constructor property
Audit.Log(Maker.prototype.constructor);
//now look for all makers prototype properties, this should list atleast "constructor"
for(var i in Maker.prototype){
Audit.Log(i);
}
爲什麼foreach循環放不出來什麼了嗎?它應該至少拿出構造函數,因爲我顯示Maker.prototype.constructor
存在。