0

I have Small application in Famo.us Framewok.

I want to declare array variable that can be use in calling js.

I have 2 .js file: (1) PageView.js (2) GetContent.js

 (1) PageView.js
     function AddContent() {
     View.apply(this, arguments);
     var getContent = new GetContent();
     getContent.AddPages();

(2)GetContent.js

 function GetContent() {
       View.apply(this, arguments);
     }
    GetContent.prototype = Object.create(View.prototype);
    GetContent.prototype.constructor = GetContent;

    GetContent.DEFAULT_OPTIONS = {};

    GetContent.prototype.AddPages = function () {

        GetData();
    }

I want to declare array variable in GetContent.js file that can be accessible in PageView.js using the object of GetContent defiened in PageView.js in above code. so that i can use like getContent.variablename[1]

how to achieve it?

ghanshyam.mirani
  • 3,075
  • 11
  • 45
  • 85

1 Answers1

1

Your GetContent class would need to have an array assigned to it's instance like so:

this.variablename[1, 2, 3];

Adding this allows your array to be attached to the class's specific instance. Otherwise, your array will only exist for the lifetime of the function scope you create it in.

You may also find that you can't access the getContent object after it's been created in your PageView for the same reason. Instead try this.getContent = new GetContent();

Lastly, try to avoid directly accessing other class's variables directly. Instead, use getter/setter methods which allow the class to share and modify their data securely.

Kraig Walker
  • 812
  • 13
  • 25