Hate Names
Hate Names

Reputation: 1606

Adding functions to object parameters

I have around 50 objects like:

object[0].one = something;
object[0].two = else;
object[0].options = whatever;

Not sure how to describe it but they each have sub parameters. I was trying to add an additional parameter that I would add manually only to those I wanted too, like so:

object[15].condition = function() { if (something) { then do something; } } ;
//and then later on in a function do
if (this.condition) {
this.condition;
}

but I can't get it to work =( Is something like this possible? Any help is greatly appreciated.

Upvotes: 0

Views: 42

Answers (1)

Igor
Igor

Reputation: 15893

if (this.condition) {
  this.condition();
}

Upvotes: 2

Related Questions