JQuery删除冗余代码

时间:2016-07-10 09:59:29

标签: javascript jquery

我在custom.js上有以下Jquery代码

methodName: function (arg, arg2){
    //equals to err in the `Meteor.call()`
    if(arg !== 'something'){
        throw new Meteor.Error('This is an error')
    }

    //insert new document
    var docId = Somethings.insert({
        fieldOne: arg,
        fieldTwo: arg2
    });

    //send email to each subscriber. I don't know your exact DB fields so, its up to you. You did this in a different call.
    var cursor = Subscribers.find();
    cursor.forEach(function(ss){
        //send email here. You can use each subscriber data like ss._id or ss.email. However you insert them...
    });


    //Equals to res in `Meteor.call()`. sends a result to the client side method call. inserted docId in this case
    return docId
},
  1. 如何删除函数中的重复代码(evt)?

1 个答案:

答案 0 :(得分:0)

感谢Andreas。这是我写的解决方案:

$(document).ready(function() {
    changeParameters();
});

// change request param
function changeParameters() {
    $('#pageSizeSelect, #sortBySelect').change(
            function(evt) {
                // ... function goes here
            });
}
// End change request param