码迷,mamicode.com
首页 > 编程语言 > 详细

第五天:内置对象(7.Javascript内置对象)

时间:2016-06-27 21:32:47      阅读:177      评论:0      收藏:0      [点我收藏+]

标签:

 

技术分享

1)中所术是内置对象,2)中为自定义对象

代码说明如下

2.1.1 定义并创建对象实例方式1,代码如下:

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>对象</title>
</head>
<body>
<script>
people= new Object();
people.name="iwen";
people.age="30";
document.write("name:"+people.name+";age:"+people.age);
</script>
</body>
</html>

 

运行结果:

技术分享

 

2.1.2 定义并创建对象实例方式2,代码如下:

 

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>对象</title>
</head>
<body>
<script>
people={name:"lucy",age:"32"};
document.write("name:"+people.name+";age:"+people.age);
</script>
</body>
</html>

 

运行结果:

技术分享

 

 

 

2.2 使用函数来创建对象,然后创建新的对象实例

 

代码如下:

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>对象</title>
</head>
<body>
<script>
function people(name,age){
this._name=name;
this._age=age;
}
son=new people("LiLei","10");
document.write("name:"+son._name+";age:"+son._age);

</script>
</body>
</html>

运行结果:

技术分享

 

犯过的错误:

son = new people("lily",20);

写成了 son = people("lily",20);

第五天:内置对象(7.Javascript内置对象)

标签:

原文地址:http://www.cnblogs.com/fenr9/p/5621480.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!