vendredi 26 avril 2019

Link object to multiple object for delegation

Folder Structure :-

ProjectModules
   |-- Input
     |-- aDelegatee.js
     |-- aDelegatee.js
   |-- Module
     |-- aDelegator.js
     |-- aDelegator.js
   |-- Helper
     |-- aDelegatee.js


All the .js have an object :-

For Eg, aDelegator.js,

var stdIn = require('../Input/aDelegatee');

var helper = require('../Helper/aDelegatee');

var obj = Object.create(helper);

var obj = {
  promptForInput: { 
    this.input = this.aPropertyInInputDelegatee; // could be present in any of the two Input folder .js file// ...,
  task1: function task_one() {
    this.aPropertyInHelperDelegatee; // pass this input array, to be used in helper sub routine.
  }
}

aDelegatee.js present in Input folder:

module.exports = { 
  pulicProperty: // ...
}

aDelegatee.js present in helper.js, this file can perform its routine using its own object input array when executed independently, aDelegator.js object input array instead, when called as a subroutine of Module folder aDelegator.js

module.exports = {
  input: [],
  pulicProperty: function {
    // use this.input  
  }    
}


How I do it:

aDelegator.js

// All code same as in aDelegator.js code before this one

var obj = {
  promptForInput: stdIn.aPropertyInInputDelegatee; // here I am using name instead of this reference
  task1: function task_one() {
    this.aPropertyInHelperDelegatee;
  }
}

I am unable to use correct this reference in aDelegatee.js of helper.js.

I don't want to use stdIn.aPropertyInInputDelegatee. should be this.aPropertyInInputDelegatee instead.

Aucun commentaire:

Enregistrer un commentaire