[英]Adding properties to Javascript object at run time
Let's say I have this function in javascript 假设我在javascript中有此功能
function EstablishUserSession(params) {
gecResult = "noResult";
params["callbackOnSuccess"] = Success;
params["callbackOnException"] = Exception;
controller.establishUserSessionIAPI(params);
return "requestSent";
}
params is an object passed in through HtmlDocument.InvokeScript.. Looks like this params是通过HtmlDocument.InvokeScript传入的对象。
{ iapiUri: "dfdfdsf", language: "en", partnerUsername: "ddddd", integrationPartnerId: 1, cleartextPassword: "dddd"}
The above works fine in Chrome and FFox. 上面在Chrome和FFox中可以正常工作。 Does not work in IE8. 在IE8中不起作用。 I get Object doesn't support property or method. 我得到对象不支持属性或方法。
function EstablishUserSession(params) {
gecResult = "noResult";
jQuery.extend(params, { callbackOnSuccess: Success, callbackOnException: Exception });
controller.establishUserSessionIAPI(params);
return "requestSent";
}
Then I changed to Jquery.extend... works fine in Chrome and FFox. 然后我改为Jquery.extend ...在Chrome和FFox中可以正常工作。 Does not work in IE8. 在IE8中不起作用。
Does anyone out there know how to correctly extend an object to add properties as above! 有没有人知道如何正确扩展对象以添加上述属性!
note: Success and Exception are just callbacks 注意:Success和Exception只是回调
您可以使用对象的新副本。
var newParams = $.extend({ newProp : value}, oldParams);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.