lundi 25 janvier 2016

Is this nested namespace inheritance pattern well implemented?

I´m trying to implement some nested namespaces with objects, and objects that inherit from those objects. I want to know if this first approach is well implemented:

// Namespaces
var firstDomain = {};
firstDomain.firstSubDomain = {};
firstDomain.firstSubDomain.secondSubDomain = {}

/*
* Base Object
*/
firstDomain.firstSubDomain.secondSubDomain.baseObject = (function(baseObject) {
  baseObject.init = function() {};

  return {
    init: baseObject.init
  }

})(firstDomain.firstSubDomain.secondSubDomain.baseObject || (firstDomain.firstSubDomain.secondSubDomain.baseObject = {}));

/*
* Extended Object
*/
firstDomain.firstSubDomain.secondSubDomain.extendedObject = (function(extendedObject) {
    extendedObject.init = function() {};
    extendedObject.init.prototype = Object.create(firstDomain.firstSubDomain.secondSubDomain.baseObject.init.prototype);
    extendedObject.init.prototype.extraFunction = function() {};

    return {
      init: extendedObject.init
    }

})(firstDomain.firstSubDomain.secondSubDomain.extendedObject || (firstDomain.firstSubDomain.secondSubDomain.extendedObject = {}))

// Objects instances

// Base object instance
var baseObject = new firstDomain.firstSubDomain.secondSubDomain.baseObject.init();

// Extended object instance and executing particular method
var extendedObject = new firstDomain.firstSubDomain.secondSubDomain.extendedObject.init();
extendedObject.extraFunction();

console.log(firstDomain);

Here is the repo link:

http://ift.tt/1QvShVR

Aucun commentaire:

Enregistrer un commentaire