<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>无标题文档</title>
</head>
<body>
<script>
var name = 'zhangsan'
var elephant = {
weight: 2,
height :2,
age : 18,
sex:'公',
color: 'gray',
ishasXiangya: '有',
eat: function eat(){
alert('eat')
},
run:function run(){
alert('run')
},
banmutou:function banmutou(){
alert('搬木头')
}
}
// 想要大象的一些体重
elephant.banmutou()
alert(elephant.color)
elephant.run()
alert(elephant['age'])
</script>
</body>
</html>
用JS 描绘一个大象对象,这个大象会搬木头
最新推荐文章于 2021-05-21 08:53:34 发布
本文通过一个具体的JavaScript示例展示了如何定义对象及其方法,并演示了如何调用这些方法来实现特定的功能,例如运行、搬木头等。同时,还介绍了如何获取对象属性。
1万+

被折叠的 条评论
为什么被折叠?



