javascript Javascript继承示例

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了javascript Javascript继承示例相关的知识,希望对你有一定的参考价值。

		var Adacta = Adacta || {};
		Adacta.BasePublication = Adacta.BasePublication || {}; // Entity Name

    Adacta.BasePublication.Form = function() {
				var self = this;
        this.Test = function () {
        	console.log("Base Test");
        }
    };

		Adacta.Publication = Adacta.Publication || {}; // Entity Name
		Adacta.OfferPublication = Adacta.OfferPublication || {}; // Entity Name   
    
    Adacta.Publication.FormLogic = function () {
        this.Test = function () {
        	console.log("Pub Test");
        }      
    };
    Adacta.OfferPublication.FormLogic = function () {};
    
    Adacta.Publication.FormLogic.prototype = new Adacta.BasePublication.Form;
    Adacta.OfferPublication.FormLogic.prototype = new Adacta.BasePublication.Form;

    //Call 1: Call overriden method
    Adacta.Publication.Form = new Adacta.Publication.FormLogic();
    Adacta.Publication.Form.Test();
    
    //Call 2: Call base method (we have not specified an override method so base method is called)
    new Adacta.OfferPublication.FormLogic().Test();

以上是关于javascript Javascript继承示例的主要内容,如果未能解决你的问题,请参考以下文章

Javascript 传播与继承

JavaScript 继承:Object.create 与 new

JavaScript继承

(知识点)JavaScript继承

JavaScript中继承的实现方式

JavaScript中继承的实现方式