/    Sign up×
Community /Pin to ProfileBookmark

superclass not accepting array defined in subclass

I’m in way over my head on this one (learning OO dev techniques) so i’m not sure i’m even describing this right. Anyway, i’m creating an array within a subclass (mySubClass()) and passing the array to the superclass (mySuperClass()) via the call method. It’s not working ? However, if i pass the array *to* the subclass and *then* to the superclass it does work…i’d much rather define it within the subclass…is it possible? Here’s what i’m trying to do…

[code]

/* Define super class */

function mySuperClass(sFoo,iBar,aMyArray){

this.myArray=aMyArray;
this.bar=iBar;
this.foo=sFoo;

if(typeof mySuperClass.initialized==’undefined’){

/* do lots of stuff */

mySuperClass.initialized=true;
}
}

/* Define sub class */

function mySubClass(sFoo,iBar){
this.myArray={
key1:’value1′,
key2:’value2′,
key3:’value3′
};
this.foo=sFoo;
this.bar=iBar;

mySuperClass.call(this,this.foo,this.bar,this.myArray); /* <- seems to break here */

if(typeof mySubClass.initialized==’undefined’){

/* do lots of stuff */

mySubClass.initialized=true;
}

}

/* Test it */

MySubClass.prototype=new MySuperClass();
var testIt=new MySubClass(‘string’,34);

[/code]

What am i doing wrong? ?

to post a comment
JavaScript

0Be the first to comment 😎

×

Success!

Help @bcamp1973 spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.25,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...