我想使用實例訪問靜態屬性。這樣javascript:如何訪問靜態屬性
function User(){
console.log('Constructor: property1=' + this.constructor.property1) ;
}
User.prototype = {
test: function() {
console.log('test: property1=' + this.constructor.property1) ;
}
}
User.property1 = 10 ; // STATIC PROPERTY
var inst = new User() ;
inst.test() ;
的東西在這裏是在jsfiddle
在我的情況,我不知道該實例屬於哪個類相同的代碼,所以我試圖用實例來訪問靜態屬性的構造函數「屬性,但沒有成功:( 這可能嗎?
不要在javascript中使用word類 – 2013-05-02 18:20:24
@Johan:這個鏈接怎麼和這裏的任何東西相關? – Bergi 2013-05-02 18:28:48