这里以创建默认对象为例
第一种方式:
<script> let obj = new Object(); obj.name = "Durant"; obj.age = 30; obj.say = function() { console.log("Hello World!"); } console.log(obj.name); console.log(obj.age); obj.say(); </script>第二种方式:
<script> let obj = {}; obj.name = "Durant"; obj.age = 30; obj.say = function() { console.log("Hello World!"); } console.log(obj.name); console.log(obj.age); obj.say(); </script>第三种方式:
<script> let obj = { name: "Durant", age: 30, say: function() { console.log("Hello World!"); } }; console.log(obj.name); console.log(obj.age); obj.say(); </script>