2013-10-15 36 views
0

我已经继承了我公司中没有人使用的旧代码库。有一个jquery插件正在使用,最少的文档。这里是我需要的部分:如何将特定属性传递给函数中的JavaScript对象

/** 
* @param {String} message  This is the message string to be shown in the popup 
* @param {Object} settings  This is an object containing all other settings for the errorPopup 
* @param {boolean} settings.close Optional callback for the Okay button 
* @returns a reference to the popup object created for manual manipulation 
*/ 
Popup.errorPopup = function(message , settings){ 

    settings = settings || {}; 

    var defaults = { 
        allowDuplicate: false, 
        centerText: true, 
        closeSelector: ".ConfirmDialogClose" 
        } 

    settings = $.extend(defaults , settings); 

    return Popup.popupFactory( message, 
           settings, 
           ".ConfirmDialogBox", 
           ".PopupContent" 
          ); 

} 

我们目前调用这个函数只是使用默认设置;他们没有经过例东西:

Popup.errorPopup('Sorry, your account couldn\'t be found.'); 

对于一个使用这个,我需要一个回调函数来传递的,当弹出关闭。根据评论,有一个settings.close参数,但我不知道如何去通过函数调用传递它。

我尝试这样做:

Popup.errorPopup('Sorry, your account couldn\'t be found.', {close: 'streamlinePassword'}); 

其中streamlinePassword是回调函数的名称。

但是得到了一个javascript错误:属性'关闭'的对象#不是一个函数。

如何将这个新的对象参数传递给函数调用?

+0

您是否尝试过使用'{收盘:streamlinePassword}',不包括引号? –

回答

0

不要传递字符串,传递函数。

样品:

function streamlinePassword() { 
// ... 
} 

Popup.errorPopup('...', {close: streamlinePassword}); 

// also possible 
Popup.errorPopup('...', { 
    close: function() { 
    } 
}); 

// also possible II 
Popup.errorPopup('...', { 
    close: function test() { 
    } 
}); 
+0

谢谢!就是这样。 – EmmyS

相关问题