JavaScript面向对象编程(2)对象上的特殊属性

释放双眼,带上耳机,听听看~!

js对象都有constructor属性,但是构造函数产生的对象和简单对象的属性有些不同,可自行运行下列代码了解


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
1<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
2<html xmlns="http://www.w3.org/1999/xhtml">
3<head>
4<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
5<title>对象上的特殊属性</title>
6</head>
7
8<body>
9<script type="text/javascript">
10function Hero(name) {
11  this.name = name;
12  this.occupation = 'Ninja';
13  this.whoAreYou = function() {
14  return "I'm " + this.name + " and I'm a " + this.occupation;
15  }
16}
17 var h1 = new Hero('Michelangelo');
18 alert(h1.constructor);//返回一个函数
19 var obj = {};//var obj = new Object();
20 alert(obj.constructor);
21
22</script>
23
24</body>
25</html>
26
27

给TA打赏
共{{data.count}}人
人已打赏
安全技术

C++遍历文件夹

2022-1-11 12:36:11

安全技术

bootstrap框架的.container 和container-fluid 类的区别

2021-12-21 16:36:11

个人中心
购物车
优惠劵
今日签到
有新私信 私信列表
搜索