var dag = {
//属性
name: 'wangcai',
age:3,
height:1.55
dogFriends:['sss','aaa'],
/*
this所在的函数在哪个对象中,this就代表这个对象
*/
//方法
eat:function (someThting) {
console.log(this.name + '吃' + someThting)
},
run:function () {
console.log(this.name + '跑')
}
};
//如何调用对象中的属性和方法
god.name = 'ojojoj';
console.log(dog.name,dog.age);
dog.eat('屎');
新的HTML中使用这个类
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
<script src="XHWDog.js"></script>
<script>
var sDog = new Dog();
sDog.name = '小狗';
sDog.age = 13;
sDog.eat('肉');
</script>
</head>
<body>
</body>
</html>
网友评论