0
Object.defineProperty(window.location, "x", function(){});

I use Object.defineProperty to add properties to objects. In Firefox and Chrome adding properties and methods to window.location works fine in this way, however in IE9 I receive an "Object doesn't support this action" error.

Object.defineProperty seems to work with other things. And adding methods via "window.location.methodName = function(){}" seems to work. However I want to add a GET property.

I am ready to just turn the property into a method, however I want to be sure it is not otherwise possible because a property is more logical in what I want it for.

  • Out of curiosity, why are you messing around with built-in objects? – Niet the Dark Absol Jun 24 '14 at 14:27
  • It seems more logical and convenient to me to add properties and methods to the relevant objects and prototypes than create them as functions or on new wrapper objects. I have heard about extending the DOM being bad but I have been mostly unconvinced that too much trouble is caused in doing so. In this scenario I am adding a searchList property which renders the search parameter as key-value pairs. Although now that I think about it I can probably just make it a static value. – user3771609 Jun 24 '14 at 16:15
  • It might be more useful to have a `parseQueryString` function, which you can either pass `location.search` to... or a string from any other source ;) – Niet the Dark Absol Jun 24 '14 at 16:31

0 Answers0