如何将特定属性传递到函数中的javascript对象
我继承了一个我公司没有人使用过的旧代码库。有一个jquery插件正在使用,只需要很少的文档。这是我需要的部分:如何将特定属性传递到函数中的javascript对象,javascript,jquery,parameters,Javascript,Jquery,Parameters,我继承了一个我公司没有人使用过的旧代码库。有一个jquery插件正在使用,只需要很少的文档。这是我需要的部分: /** * @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 * @par
/**
* @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.');
对于这种用法,我需要在弹出窗口关闭时传入一个回调函数。根据注释,有一个设置。关闭
参数,但我不知道如何通过函数调用传递它
我试过这个:
Popup.errorPopup('Sorry, your account couldn\'t be found.', {close: 'streamlinePassword'});
其中streamlinePassword
是回调函数的名称
但是得到了一个javascript错误:object#的属性“close”不是函数
如何将这个新对象参数传递到函数调用中?不要传递字符串,传递函数 样本:
function streamlinePassword() {
// ...
}
Popup.errorPopup('...', {close: streamlinePassword});
// also possible
Popup.errorPopup('...', {
close: function () {
}
});
// also possible II
Popup.errorPopup('...', {
close: function test() {
}
});
您是否尝试过使用不带引号的
{close:streamlinePassword}
?