0

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.

5
  • 1
    how does object[15] turn into this? Commented Jun 21, 2013 at 0:26
  • 1
    If you're calling a function that's a property of an object, you still have to add the parentheses. this.condition() instead of this.condition. Commented Jun 21, 2013 at 0:27
  • Amazing, bfuoco. I don't get why I don't at least try this stuff when I try at least everything else, for some reason I was just sure that wouldn't work..damnit. What a waste of time and a question, sorry for the trouble. Thanks so much, would have chose this as the best answer if it wasn't a comment, thanks again. Commented Jun 21, 2013 at 0:29
  • @Musa a little surprised you have 35k rep and are asking me that, I mean no offense at all. My objects are divs and they have a .onmousedown to call a function. using this, works in that function. Commented Jun 21, 2013 at 0:31
  • 35k rep doesn't give you psychic powers Commented Jun 21, 2013 at 0:34

1 Answer 1

2
if (this.condition) {
  this.condition();
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.