Search code examples
javascriptjqueryinternet-explorerinvokescript

Adding properties to Javascript object at run time


Let's say I have this function in 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

{ iapiUri: "dfdfdsf", language: "en", partnerUsername: "ddddd", integrationPartnerId: 1, cleartextPassword: "dddd"}

The above works fine in Chrome and FFox. Does not work in 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. Does not work in IE8.

Does anyone out there know how to correctly extend an object to add properties as above!

note: Success and Exception are just callbacks


Solution

  • You could use a new copy of the object..

    var newParams = $.extend({ newProp : value}, oldParams);