After doing some calculation, I’m here anyway ^_^
Wuyou~~It’s been a long time….. Post something about the principle,
]
(stroll's follow-up)
Of course, you can also use the following methods without "plug-in"... However, you need to use Script5.5 to use
For example, call method and apply method... The following is how to use call The method to implement
apply is similar, except that the parameters called later are arrays. For details, you can refer to the MSScript5.6 instructions.
Bencalie, do you still remember when you told me how to use call apply? Is this answer satisfactory this time?
If you need to introduce external Js, you need to refresh to execute
]
(stroll's follow-up)
Pay attention to the this.Prototype variable of the so-called "inherited object" (I didn't pay attention at first, thinking it was a keyword... which made me struggle to find information)
this. Prototype = new JSObject(); // Note: This is not a lowercase prototype
this.Prototype.Speak = function(s){.....}
Feedback directly after constructing the object return this .Prototype In fact, this is the JSPObject object.
is not a JSHuman object, so var o = new JSHuman();
If you need to introduce external Js, you need to refresh to execute
]
(Bencalie’s post)
stroll, I am very satisfied with your answer.
You raised the question again, so here Base.call(this, v_sName) is used as Base.apply(this), how do I pass v_sName to Base.BaseName, but I am a little bit confused about the use of apply. It’s hard to understand.
Finally, Base.apply(this, [v_sName]) was used to pass the array successfully
So it looks like call and apply are just different parameters?
[Ctrl A Select all Note:
If you need to introduce external Js needs to be refreshed to execute
]
[Ctrl A to select all Note: If you need to introduce external Js, you need to refresh to execute ]
(stroll的跟贴)
To bencalie ,是的,的确仅仅如此
不过不要认为apply这样是麻烦,其实如果两个对象的构造参数顺序一样的话,可以这么来
Base.apply(this, arguments) 很方便吧?
附上:(因为30秒才一贴~~)
不过你那里添加一个 new Base() 是认为无法继承的做法,其实是可以继承方法的,O.BaseMethod() 的调用就是了 ^_^
to:bencalie(Roman的跟贴)
基对象的方法被overwrite了.为什么stroll说 var o = new JSHuman(); o 这个实例是无法访问 JSHuman 的成员的
請看如下代碼:
stroll,方法的確繼承過來了,但我在Son對象的搆造函數裏重寫了BaseMethod()
事實上O.BaseMethod()這樣調用已經不是Base對象的BaseMethod()方法了,而是Son對象的BaseMethod()方法,所以我把Base的一個實例儅作Son的成員base,使用
Son實例.base.BaseMethod()
的格式來引用Base的BaseMethod()方法
另外,我喜懽這句:Base.apply(this, arguments)
呵呵……收到~~(stroll的跟贴)
虽然说JS是没有指针了…… 不知道同时构造一个“父对象”,一个“子对象” 再有一个函数传递一个对象参数,这个参数使用父子共有的方法,是不是能够分别调用相应的方法呢? 还未了解JS 的 this 是不是相当于 虚拟地址的指针呢?
所以替换了方法才能解决上面的疑惑(虽然这个迷惑是菜了点,不过符合逻辑:)
还有……如果里面成员有构造对象的函式,是不是也会像c++一样先构造对象,然后再执行其他函式呢? 这个可能或则肯定是按照从上到下了~~~~语言规定?没试过
有没有试过多个父对象的继承呢?不过也不难想到这个一步……(树状继承)
这些就是偶的疑问啦,呵呵……