Ext.extend方法是用來(lái)實(shí)現(xiàn)類的繼承,。
extend(Object subclass,Object superclass,[Object overrides] : Object
第一個(gè)參數(shù):子類
第二個(gè)參數(shù):父類
第三個(gè)參數(shù):要覆蓋的屬性,。
這里需要強(qiáng)調(diào)一下,子類繼承下來(lái)的是父類中通過(guò)superclass.prototype方式定義的屬性(包括用此方法定義的函數(shù)),。
例子如下:
- <script type="text/javascript">
- function S(){
- }
- S.prototype.s = "s";
- S.prototype.s1 = "s1";
- function C(){
- this.c = "c";
- this.c1 = "c1";
- }
- Ext.extend(C,S,{s1:"by c overload"});
- var c = new C();
- alert(c.s);
- alert(c.s1);
- </script>
如果按下面這個(gè)方式寫(xiě)就會(huì)提示c.s沒(méi)有定義(undefind):
- <script type="text/javascript">
- function S(){
- this.s = "s";
- this.s1 = "s1";
- }
- function C(){
- this.c = "c";
- this.c1 = "c1";
- }
- Ext.extend(C,S,{s1:"by c overload"});
- var c = new C();
- alert(c.s);
- alert(c.s1);
- </script>
也可以通過(guò)如下方式來(lái)實(shí)現(xiàn)類的繼承
- <script type="text/javascript">
- function S(){
- }
- S.prototype.s = "s";
- S.prototype.s1 = "s1";
- C = Ext.extend(S,{s1:"by c overload"});
- var c = new C();
- alert(c.s);
- alert(c.s1);
- </script>
此時(shí),,C是子類,S是父類