JavaScript继承 类变量(静态变量)和实例变量

function Phone(NUM,TITLE){

	this.num = NUM;//实例变量,用"对象.属性"访问

	this.title = TITLE;

	this.print = function (){

		alert("num:"+this.num+"title:"+this.title);

	}

}

Phone.size = 111 ;//类变量,只能用"类名.属性"访问

Phone.prototype.color = "red";//实例变量,用"对象.属性"访问
var ph = new Phone(123,"aa");

ph.print();//num:123title:aa
alert(Phone.size);//111
alert(Phone.color);//undefined
alert(ph.size);//undefined 
alert(ph.color);//red 

 

你可能感兴趣的:(JavaScript)