我有一些代码作为我正在处理的 javascript 周末项目的一部分。我的问题在最后一行。据我所知,我应该可以只打电话Floater.create()
而不必打电话Floater.prototype.create()
。为什么我需要额外的.prototype
?没有它,将引发错误:Floater() has no method "create"
function Floater(){}
Floater.prototype.create = function(){
//do stuff
}
$(document).ready(function(){
//do stuff
runStartup();
});
function runStartup(){
loginFloater = new Floater;
Floater.prototype.create();
// as far as I know, this should run as just Floater.create(),
// but that throws an error.
}