0
function test(){
}
test.prototype.doSomething = function() {
return true;
}
在此示例中,我可以訪問test.doSomething();但是輸入t.doSomething()會很酷。 是否有可能爲我的班級測試定義類似別名的內容?Javascript原型:對同一類使用多個名稱
function test(){
}
test.prototype.doSomething = function() {
return true;
}
在此示例中,我可以訪問test.doSomething();但是輸入t.doSomething()會很酷。 是否有可能爲我的班級測試定義類似別名的內容?Javascript原型:對同一類使用多個名稱
引用它在另一個變量。 test
仍然存在。這只是變量t
引用它。
var t = test;
test.doSomething(); //test does something
t.doSomething(); //t does the same thing
@約瑟夫的答案是當場就,但它也沒有價值,你的test
函數可以被調用爲Constructor via the new
keyword:
var t = new test();
t.doSomething();