繁体   English   中英

我怎样才能让JSLint停止抱怨Ember.js“.property()”?

[英]How can I get JSLint to stop complaining about Ember.js “.property()”s?

如何让JSLint停止在我的模型定义中抱怨Ember.js“.property()”?

例如,当给出时:

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

JSLint抱怨:

Unexpected '.'.

在.property()调用的行上。 每次出现“.property()”都会发生这种情况,这会使JSLint输出充满“噪音”,并且不会完全有用......

Ember 记录了以下方法以避免函数原型扩展。

而不是.property() ,使用Ember.computed()

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

而不是.observes() ,使用Ember.observer()

fullNameDidChange: Ember.observer('fullName', function() {
  console.log("Full name changed");
})

我的解决方案是将其转换为:

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

我首先将“属性”方法添加到Ember(在启动我的应用程序之前):

Em.property = function (func) {
    var params = Array.prototype.slice.call(arguments, 1);
    return Function.prototype.property.apply(func, params);
}; 

目前无法配置此功能。 您可以手动更改jslint。

在第3397行(版本2013-11-23)的jslint.js ,您将找到这些行

    case '.':
        if (peek().string !== 'bind' || peek(1).id !== '(') {
            next_token.warn('unexpected_a');
        }
        break;

请注意,如果声明和警告将消失!

    case '.':
        // if (peek().string !== 'bind' || peek(1).id !== '(') {
        //     next_token.warn('unexpected_a');
        // }
        break;

Arne的解决方案正沿着正确的轨道前进。 但JSlint不会警告你一些事情。 而不是评论相关的线条改变jslint.js第3387 jslint.js

case '.':
    if (peek().string !== 'bind' || peek(1).id !== '(') {
        next_token.warn('unexpected_a');
    }
    break;

对此(第2行)

    case '.':
        if (peek().string !== 'bind' && peek().string !== 'property' || peek(1).id !== '(') {
            next_token.warn('unexpected_a');
        }
        break;

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM