Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I get JSLint to stop complaining about Ember.js ".property()"s?

How can I get JSLint to stop complaining about Ember.js ".property()"s in my model definitions?

E.g., when given:

isBlah: function() {
    "use strict";
    ...
}.property("foo", "bar").cacheable()

JSLint complains about:

Unexpected '.'.

on the line with the .property() call. This happens for every occurrence of ".property()" which makes JSLint output full of "noise" and less than fully helpful...

like image 966
Mike F Avatar asked Dec 06 '25 10:12

Mike F


2 Answers

Ember documents the following method to avoid the function prototype extensions.

Instead of .property(), use Ember.computed():

fullName: Ember.computed('firstName', 'lastName', function() {
  return this.get('firstName') + ' ' + this.get('lastName');
})

Instead of .observes(), use Ember.observer():

fullNameDidChange: Ember.observer('fullName', function() {
  console.log("Full name changed");
})
like image 114
pbatey Avatar answered Dec 07 '25 22:12

pbatey


My solution was to convert it to:

isBlah: Em.property(function() {
    "use strict";
    ...
}, "foo", "bar").cacheable()

Where I first add the 'property' method to Ember (before starting my app):

Em.property = function (func) {
    var params = Array.prototype.slice.call(arguments, 1);
    return Function.prototype.property.apply(func, params);
}; 
like image 34
shex Avatar answered Dec 07 '25 22:12

shex



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!