Sails hook控制器坏注册

时间:2015-03-20 07:00:31

标签: hook mootools sails.js controllers

我正在使用带有风帆的mootools服务器端。这让我创建了可以扩展的类和更多的功能,但是当sails hook控制器尝试注册控制器动作时会出现问题。他们使用._each和mootools对象具有类似$ constructor和sails的属性尝试将其注册为操作然后错误....如何使用mootools每个方法覆盖它? mootools每个方法跳过这个属性,然后一切正常

谢谢!

1 个答案:

答案 0 :(得分:2)

是的,这是帆的问题。 _.each用于迭代对象,但它可以在Arrays上工作,因为它们实际上是具有类似数组属性的对象。它应该更改为_.forEach

同时,由于你在nodejs中,你可以配置Array原型来隐藏这样的枚举:

var foo = ['one','two'],
    key;

for (key in foo){
    // lists all mootools methods and properties as well as 0, 1
    console.log(key, foo[key]); // needs hasOwnProperty etc, ppl complain.
}

// protect enumerables under ES5 in Array
(function(){
    // set mootools expandos to non-enumerables under ES5
    var key,
        a = [];

    for (key in a) a.hasOwnProperty(key) || Object.defineProperty(Array.prototype, key, {
        enumerable:false
    });
}());

console.info('trying again...');

for (key in foo){
    console.log(key, foo[key]);    
}

我刚才写过这篇文章 - http://fragged.org/hiding-enumerables-after-mootools-changes-prototypes_1552.html

mootools-core 1.6存在一个问题 - https://github.com/mootools/mootools-core/issues/2665 - 应该尽快完成。