JS创建对象的方式
摘要:
一、创建对象的方式:1、工厂方式:function createCar(colors,doors){var tempCar = new object();tempCar.colors = colors;tempCar.doors = doors;tempCar.showColor = function showColor(){alert(this.color);};}缺点:不像常用的面向对象声明的方式;每声明一个Car实例,就要创建多一个showColor函数,不能复用,浪费内存。2、构造函数的方式。function Car(colors,doors){this.colors = colors 阅读全文
posted @ 2012-02-21 11:12 batigol 阅读(145) 评论(0) 推荐(0)
浙公网安备 33010602011771号