二十二、JavaScript之在对象中写函数

一、代码如下

 

二、效果如下

<!DOCTYPE html>
<html>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<body>
<h1>我的第一张网页</h1>

<p id="demo"></p>

<script>

var person = {
    firstName: "Bill",
    lastName: "Gates",
    age: 18,
    eyeColor: "blue",
    fullName: function(){
        return this.firstName + " " + this.lastName;
    }
};
document.getElementById("demo").innerHTML = person.fullName();
 
</script>

</body>
</html>

 

posted @ 2019-08-07 12:52 像一棵海草海草海草 阅读(...) 评论(...) 编辑 收藏