javascript - Can't set customized property on objects -


i'm trying define customized property called userdata, objects location.hash, doesn't work, got false, false 2 alert calls.

        object.defineproperty(object.prototype, "userdata", {             value: false,             writable: true,             enumerable: true,             configurable: true         });          alert (location.hash.userdata);         location.hash.userdata = true;         alert (location.hash.userdata); 

is immutable?

if define own object, i.e

var = {}; a.userdata = true; 

it set correctly, couldn't why former example doesn't work

it's normal first alert gives false since default value userdata false.

however, location.hash.userdata = true; not work because when treat location.hash primitive string object using dot notation, wrap primitive value in string primitive wrapper , wrapper object discarded after, it's same doing new string(location.hash).userdata = true;

since cannot location.hash = new string(location.hash), have store properties on object because location.hash immutable.


Comments

Popular posts from this blog

android - getbluetoothservice() called with no bluetoothmanagercallback -

sql - ASP.NET SqlDataSource, like on SelectCommand -

ios - Undefined symbols for architecture armv7: "_OBJC_CLASS_$_SSZipArchive" -