[英]How to call Parent class function inside child class in javascript
這是我的代碼,我有兩個class 1.分類帳,其中有一個函數first()。 2.供應商無功能。
現在我想在供應商類中調用first()函數。
https://gyazo.com/bea7ef497b58d390e279d3e2ea668431
var ledger = function(){};
ledger.prototype = {
first : function(){
alert('first function is being called!');
}
} // END OF ledger CLASS
var supplier = function(){}
supplier.prototype = {
first();
} // END OF supplier CLASS
jQuery(function(){
// INHERITANCE
supplier.prototype = create.Object(ledger.prototype);
});
提前致謝
var Ledger = function() {};
Ledger.prototype.first = function () {
console.log("First!");
};
var Supplier = function () {
Ledger.call(this);
};
Supplier.prototype = Object.create(Ledger.prototype);
Supplier.prototype.constructor = Supplier;
Supplier.prototype.second = function () {
console.log("Second!");
this.first();
};
var supplier = new Supplier();
// First!
supplier.first();
// Second!
// First!
supplier.second();
console.log(supplier instanceof Ledger); // true
console.log(supplier instanceof Supplier); // true
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.