Alexandros K
Alexandros K

Reputation: 947

Computed property returns a function? Not sure if me or a bug in the latest ember.js

Hey y'all I'm having the weirdest issue in my ember code. (1.0-pre4)

This seemingly innocuous code is not working at all as expected:

a = Ember.Controller.create({ 
        hello: function(){ 
            return "hello"; 
        }.property() 
    } )

when I do a.get("hello") , instead of returning hello, it returns a function!

Here is a dump:

i
_cacheable: true
_dependentKeys: Array[0]
func: function (){ return "hello"; }
__proto__: Ember.Descriptor

In handlebars templates it shows up as [object Object]

I'm not by any means a seasoned Ember programmer.. but I am pretty sure this used to work differently. Has something changed?

However, I have noticed that when I call a.hello.func() then that returns hello!

This definitely doesn't make any sense. Could I be doing something wrong, or is there an issue with Ember??

Any help is appreciated. I know this question is similar to some others, but I have no other way to put down all my information in a cohesive fashion in the answers of the others.

Edit: I think I know what the issue is.. You can't specify computed properties in the 'create' function. Will try 'extend' first and report back!

Upvotes: 1

Views: 436

Answers (1)

Mike Grassotti
Mike Grassotti

Reputation: 19050

As of ember 1.0.0-pre.3, you can no longer define computed properties via Object.create(). In most cases you should be using extend, but if you need the old behavior can use createWithMixins().

See also:

https://github.com/emberjs/ember.js/commit/c1c720781c976f69fd4014ea50a1fee652286048

Ember.Object.create no longer supports defining methods that call _super

Upvotes: 3

Related Questions