JS 创建对象
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>JS 中创建对象</title>
<script type="text/javascript">
//this 所在函数属于哪个对象.他就代表哪个对象
//创建对象
var dog = {
age:10,
weight:20,
height:1.2,
dogFriends:['a','b','v','e','r'],
name:'dahuang',
//方法
eat: function (something) {
console.log( this.name + '吃' + something);
},
run:function (somewhere) {
console.log(this.name + '在' + somewhere +'跑');
}
};//object
console.log(typeof dog)
//输出够对象的属性与行为
console.log(dog.age, dog.eat('肉'),dog.run('操场'))
</script>
</head>
<body>
</body>
</html>
批量创建对象

image.png

image.png
网友评论