Hi Steve,
So does each widget get it's own Javascript execution/environment where any modification to built-in object would not affect other widgets?
Yes, that's correct.
You know, I was messing around some more with augmenting the native types. I discovered that while my code above works, if I then go to another view my widget will throw an exception. This could have been what sax was referring to. This is because augmenting Object.prototype with a function will throw an exception when parsed by the JSON object. We're looking into it. Digging a little more, I also discovered that augmenting Object.prototype with a non-function data type throws an exception in the framework. This will be fixed in a future release.
So, in light of everything, my suggestion is to not augment native types. As an alternative, bind the method to the object itself as a class method, i.e.:
CODE
Object.serialize = function (o) {
var str = [];
for (var p in o) if (typeof o[p] != 'function') str.push(p + "=" + encodeURIComponent(o[p]));
return str.join("&");
};
var o = {
firstName: "Joe",
lastName: "Public",
team: "Phillies"
};
Object.serialize(o);
But as Jeremy said above, using JSON for serializing is really the best choice.
- Ben