//one var user = function(){ this.name=""; this.id=""; }; user.add = function(){ console.log("add"); }; user.delete = function(){ console.log("delete"); }; user.prototype = user; window.user = new user();
第二种方式不使用new关键字直接将user对象暴露到window对象中
//two var user = { name:"", id:"" }; user.add = function(){ console.log("add"); }; user.delete = function(){ console.log("delete"); }; window.user = user;
使用
<button>增加</button> <button>删除</button>
您可能感兴趣的文章: