arrays and objects

+4 Nathan Ellis · August 22, 2016
How can I add an array inside a constructor function?

Post a Reply

Replies

Oldest  Newest  Rating
+5 pwntastic _ · August 23, 2016
Do you mean to pass in as an argument or what? If so, something like this:


var test = new Testing(['testing', 'testin2']);

var Testing = function (testArray) {
    self = {};
    
    return self;
};
+2 Sho Carter · September 10, 2016
@pwntastic, your answer would create an error, because you're trying to instantiate a new instance of a object that hasn't been declared yet; so to answer your question Nathan, it'd really be best to do what @pwntastic said with this bit of correction:

var Testing = function (testArray) {
console.log( testArray );
};


var test = new Testing(['testing', 'testin2']);
0 ramadhani khamisi · October 2, 2016
'var test = new Testing(['testing', 'testin2']);

var Testing = function (testArray) {
    self = {};
    
    return self;
};'
  • 1

Javascript

130,957 followers
About

A scripting language that is added to standard HTML to create interactive effects, apps, games for the browser.

Links
Moderators