Skip to content

Instantly share code, notes, and snippets.

@jbeard4
Created June 18, 2012 13:27
Show Gist options
  • Save jbeard4/2948362 to your computer and use it in GitHub Desktop.
Save jbeard4/2948362 to your computer and use it in GitHub Desktop.
This illustrates how JScript.NET fails to extend intrinsic object prototypes.
//jscript.net does not support extending intrinsic object prototypes
Object.prototype.foo = 1;
var x = {};
print("Object.prototype.foo -",Object.prototype.foo); //should print 1. in jscript.net: undefined
print("x.foo - ",x.foo); //same
Object.prototype["foo"] = 1;
var y = {};
print("Object.prototype.foo - ",Object.prototype.foo); //same
print("x.foo - ",x.foo); //same
print("y.foo - ",y.foo); //same
try {
Array.prototype.bar = 2; //this blows up
}catch(e){
print("Exception :",e.message);
}
try {
Array.prototype["bar"] = 2; //this blows up
}catch(e){
print("Exception :",e.message);
}
var z = [];
print("z.bar - ",z.bar); //undefined
print("Array.prototype.bar - ",Array.prototype.bar); //undefined
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment