<!DOCTYPE html>
<html>
<head lang="en">
<meta charset="UTF-8">
<title></title>
</head>
<body>
</body>
</html>
<script>
function Person(name,age){ //构造函数就是一个普通函数,为了和普通函数区别,第一个字母大写。
this.name = name;
this.age = age;
this.showName = function () {
alert("我的名字是"+name);
}
this.showAge = function () {
alert("我的年龄是"+age);
}
}
var demo = new Person("刘德华",66);
console.log(demo.name);//提倡用.调用
console.log(demo["name"]);
</script>
tx6-new关键字来声明对象
最新推荐文章于 2024-03-17 17:52:08 发布