1

I have a model with two arrays, bright and normal. Each array includes objects which are representing colors. I want to implement in model a method allowing to set some properties (for example hue) of this colors. So I wrote this:

setHue: function(hue) {
    _.each([this.get('brigth'), this.get('normal')], function(colors) {
        _.each(colors, function(color) {
            color.setHue(hue + this.getHue());
        });
    });
},

I think it's clear - I try to iterate over every color in both bright and normal arrays. And it doesn't update colors inside these arrays. This color inside _.each seems to have a new value, but it looks it's only a copy of color, not a reference. Do anyone know how to do what I want? I mean with _.each loop, I don't wanna mess up with for, length and indexes.

1
  • 1
    YES! Thank you! "The darkest place is under the candlestick". normal was loging me proper values inside a loop, and I was checking bright after all. Commented Aug 17, 2012 at 2:58

2 Answers 2

1

Bright is misspelled. You entered brigth.

Sign up to request clarification or add additional context in comments.

Comments

0

Hm, I think you have a general problem here. Let's try with an example:

this.get('brigth')

will return an array, not a model, correct?

If so,

_.each([this.get('brigth'), this.get('normal')], function(colors) { ...

will loop over an array of arrays, i.e. colors will get an array, not a model nor a collection. Consequently, color will be a item of an array (I assume a string). Thus color with not have a method setHue.

Additionally, Paul is right as well this.getHue() this does not refer to a model, since you are switching context twice (once for each each-Loop). I hope I did not get it totally wrong here.

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.