5

Ember uses something like:

val: function(){ 
    ...
}.property()

and things like:

func: function(){
}.observes('someValue')

I think the fact that you can add a property to the end of a function is quite neat and would like to replicated it.However, I could not find where either of those things are implemented in the source and am wondering if anyone knows?

Also, more importantly, what exactly is going on here?

xiaolingxiao
  • 4,793
  • 5
  • 41
  • 88

1 Answers1

5

It's one of the Functions methods, just like call or bind.

You can add other methods by extending the native Function.prototype object. Whether that is a good practice is discussable, though; also have a look at these articles.

Community
  • 1
  • 1
Bergi
  • 630,263
  • 148
  • 957
  • 1,375
  • 2
    If you would like to see how Ember implements this, see https://github.com/emberjs/ember.js/blob/master/packages/ember-runtime/lib/ext/function.js. Also note that if you conclude this is a not a good idea, Ember makes this behavior configurable by setting `Ember.EXTEND_PROTOTYPES` to false. – Luke Melia Dec 13 '12 at 12:17