Adding Prototype to JavaScript Object Literal
问题 STORE = { item : function() { } }; STORE.item.prototype.add = function() { alert(\'test 123\'); }; STORE.item.add(); I have been trying to figure out what\'s wrong with this quite a while. Why doesn\'t this work? However, it works when I use the follow: STORE.item.prototype.add(); 回答1: The prototype object is meant to be used on constructor functions, basically functions that will be called using the new operator to create new object instances. Functions in JavaScript are first-class objects,