是否有可能在javascript中獲取類內部類的名稱?這對於在我的中間件中動態創建的類的遞歸會很有用。 認爲這是一個非常不恰當崗位 - 讓我更好地確定我要解決的問題:獲取在構造函數本身內的原型構造函數的名稱在javascript中
MyClass = function(){
this.classname = ??? // Here is required and needed to store as a property
}
MyClass.prototype.log = function(){
alert(this.classname); // The alert should be MyClass
}
var myClassObj = new MyClass();
myClassObj.log();
的Javascript沒有課程。 – 2013-05-11 18:20:34
@ alex23:https://github.com/raganwald/homoiconic/blob/master/2013/02/prototypes.md – 2013-05-11 18:28:15
你可以稱它爲類或不是。 JavaScript沒有那個關鍵字(儘管它是保留的),但是你可以像使用原型的Java類一樣獲得相同的功能。對於面向對象的人來說,「類」比「與同一個原型對象相關聯的對象」要容易得多。 – 2013-05-11 18:31:07