Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ES5 getters on an Ember.Object only ever return first computed value #12940

Closed
chrisjshull opened this issue Feb 9, 2016 · 6 comments
Closed

Comments

@chrisjshull
Copy link

var i = 0;
var obj = Ember.Object.extend({
    get index() {
        return i++;
    }
}).create();
console.log(obj.index); // 0
console.log(obj.index); // 0 -> should be 1

Compare to not extending Ember.Object:

var i = 0;
var obj = {
    get index() {
        return i++;
    }
};
console.log(obj.index); // 0
console.log(obj.index); // 1

Ember 2.3.0

@chrisjshull
Copy link
Author

Oh, and just in case people were curious, using .get doesn't help:

var i = 0;
var obj = Ember.Object.extend({
    get index() {
        return i++;
    }
}).create();
console.log(obj.get('index')); // 0
console.log(obj.get('index')); // 0

I wouldn't expect it to though. It looks like Ember is doing a 1-time evaluation of the property at mergeMixins time. Anything after that resolves to that "cached" value.

@stefanpenner
Copy link
Member

fixed (for objects, not mixins) in master

@chrisjshull
Copy link
Author

awesome! any chance of a commit or PR link?

@stefanpenner
Copy link
Member

#12491

@rwjblue
Copy link
Member

rwjblue commented Feb 10, 2016

I believe it is also included in 2.4.0-beta.2

@chrisjshull
Copy link
Author

Can we reopen this? The snippet above is not fixed (Ember 2.8.0).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants