2、ass , { /**/ });Ext . extend ( MyClass , SuperClass , { /**/ }); 下面来个具体示例:var a = function ( id ){ this . id = id ;}a . prototype = { tostring : function (){ return this . id ; }}; b = function ( id ){ b . superclass . constructor . call
3、 ( this , id );}Ext . extend ( b , a , { tostring : function (){ return String . format ( "b:{0}" , this . id ); }});// 测试一下var obj1 = new a ( "obj1" );alert ( obj1 . tostring ());var obj2 = new b ( "obj2" );alert ( obj2 . tostring ());或者下面的代码,可以得到同样的效果
4、:var a = function ( id ){ this . id = id ;}a . prototype = { tostring : function (){ return this . id ; }}; b = Ext . extend ( a , { tostring : function (){ return String . format ( "b:{0}" , this . id ); }});// 测试一下var obj1 = new a ( "obj
5、1" );alert ( obj1 . tostring ());var obj2 = new b ( "obj2" );alert ( obj2 . tostring ()); 一个错误例子下面看个示例:BaseClass = function () { this . f1 = function () { alert ( "f1inbase" ); } this . f2 = function () { alert ( "f2inbase" ); }} ChildClas
6、s = function () { ChildClass . superclass . constructor . call ( this );} Ext . extend ( ChildClass , BaseClass , { f1 : function () { alert ( "f1inchild" ); }, f3 : function () { alert ( "f3inchild" ); }}); var b = new ChildClass
7、();b . f1 ();b . f2 ();b . f3 (); 可以去执行一下,可以发现 f1 的执行结果仍然是 "f1inbase" 。并没有真正的达到 override 的效果。 Ext.extendputsthepropertiesspecifiedinthe3rdargumentintothe subclass's prototype 也就是说:第三个参数里面的函数被放置在了子类的 prototype 中。而在 ChildClass.superclass.constructor.call(this); 这句上, B