日期:2014-05-16  浏览次数:20364 次

// js 原型继承
function A (){this.name='A'}
function _extend(Class,parentClass){
	if (typeof parentClass == "function"){
		Class.prototype = new parentClass();
	}
	return Class ;
}

var B = _extend(function (){this.name='B'},A);
var bORef = new B();
log(bORef);
log(bORef instanceof A);

var C = _extend(function (){this.name='C'},B);
var cORef = new C();
log(cORef);
log(cORef instanceof A);

var D = _extend(function (){this.name='D'},C);
var dORef = new D();
log(dORef,);
log(dORef instanceof A);

?

1 楼 vb2005xu 2010-06-18  
js 闭包的一个例子

function bibao(){
  var param = 21 ;
  this.changeParam = function(num){
     param = num ;
  }; 
  this.alert = function(){ alert(param)};
}

var test = new bibao();
test.alert();
test.changeParam(123);
test.alert();