Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do you replicate something like function(){ ... }.property() in javascript like in Ember.js?

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?

like image 224
xiaolingxiao Avatar asked Dec 12 '12 15:12

xiaolingxiao


1 Answers

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.

like image 176
Bergi Avatar answered Sep 22 '22 17:09

Bergi