js对象字面量的demo
<html> <body> <form> <input type="button" value="add" onclick="javascript:cart.add()"/> <input type="button" value="delete" onclick="javascript:cart.del()"/> <input type="button" value="update" onclick="cart.update()"/> <input type="button" value="name" onclick="javascript:alert(cart.name)"/> <input type="button" value="name" onclick='javascript:alert(cart["name"])'"/> <input type="button" value="caller" onclick='javascript:cart.callcart()'"/> </form> <script> var cart = { add: function(){ alert("add"); }, del: function(){ alert("delete"); }, update: function(){ alert("update"); }, name: "张三", callcart: function(){ // 对于当前字面量对象的调用,要加this关键字 this.add(); } }; </script> <body> </html>