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

javascript对象学习笔记

时间:2014-10-06 16:12:20      阅读:151      评论:0      收藏:0      [点我收藏+]

标签:javascript对象学习笔记

多的不说,直接上练习例子:

1.对象的属性、创建、构造函数、方法

<html xmlns="http://www.w3.org/1999/xhtml">

<body>

<script type="text/javascript">

//函数:用作对象的方法
function Rectangle_area() {return this.width * this.height;}
function Rectangle_perimeter() {return this.width * 2 + this.height * 2;}
function Rectangle_set_size(w, h) { this.width = w; this.height = h;}
//object_Rectangle 的构造函数
function object_Rectangle(w, h) 
{
	//初始化对象的属性
	this.width = w;
	this.height = h;
	//定义对象的方法
	this.area = Rectangle_area;
	this.perimeter = Rectangle_perimeter;
	this.set_size = Rectangle_set_size;
}
//创建object_Rectangle对象,调用它的方法
var r = new object_Rectangle(3, 4);
var a = r.area();
document.write(a);
</script>

</body>
</html>


javascript对象学习笔记

标签:javascript对象学习笔记

原文地址:http://blog.csdn.net/u014761420/article/details/39828355

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