您现在的位置:
365建站网 >
365文章 > [JavaScript]类之二---javascript 类定义4种方法
[JavaScript]类之二---javascript 类定义4种方法
文章来源:365jz.com 点击数:
257 更新时间:2009-09-12 16:51
参与评论
javascript 类定义4种方法
Java代码
-
-
-
-
-
- function createCar(color,doors,mpg){
- var tempCar = new Object;
- tempCar.color = color;
- tempCar.doors = doors;
- tempCar.mpg = mpg;
- tempCar.showCar = function(){
- alert(this.color + " " + this.doors);
- }
- return tempCar;
- }
-
-
-
-
- function Car(color,doors,mpg){
- this.color = color;
- this.doors = doors;
- this.mpg = mpg;
- this.showCar = function(){
- alert(this.color);
- };
- }
-
-
-
- function Car(color,doors,mpg){
- this.color = color;
- this.doors = doors;
- this.mpg = mpg;
- this.drivers = new Array("nomad","angel");
- }
-
- Car.prototype.showCar3 = function(){
- alert(this.color);
- };
-
-
-
-
- function Car(sColor, iDoors, iMpg) {
- this.color = sColor;
- this.doors = iDoors;
- this.mpg = iMpg;
- this.drivers = new Array("Mike", "Sue");
- }
-
- Car.prototype.showColor = function () {
- alert(this.color);
- };
-
-
-
- function Car(sColor, iDoors, iMpg) {
- this.color = sColor;
- this.doors = iDoors;
- this.mpg = iMpg;
- this.drivers = new Array("Mike", "Sue");
-
- if (typeof Car._initialized == "undefined") {
-
- Car.prototype.showColor = function () {
- alert(this.color);
- };
-
- Car._initialized = true;
- }
- }
如对本文有疑问,请提交到交流论坛,广大热心网友会为你解答!! 点击进入论坛
------分隔线----------------------------