0
我有一個私有類rs。其定義後,我有以下代碼。執行原型函數
rs.prototype = new EventTarget();
rs.prototype.constructor = rs;
EventTarget定義了一個fire方法。從RS方法中,我試圖調用self.fire(..) 呼叫崩潰,並「不確定是不是一個函數」
在Chrome當我把鼠標放在自它給
__proto__: rs
開,我有
constructor: function rs(...
下是
prototype: EventTarget
下面是
__proto__: EventTarget
下是
fire: function (..
如何撥打火警功能?有沒有問題,因爲這是一個私人課程?
你可以給我們一個小提琴,讓它更容易跟蹤問題嗎? –
嘗試使用'rs.prototype = Object.create(EventTarget.prototype)'設置繼承的原型部分'可以通過rs在rs構造函數中具有'EventTarget.call(this,arguments)'來使用EventTarget構造函數。構造函數應該以大寫字母開頭,所以rs應該是Rs。更多關於這裏的構造函數和原型:http://stackoverflow.com/questions/16063394/prototypical-inheritance-writing-up/16063711#16063711 – HMR