I was wondering if there is a way to disallow the following in javascript:
var c = new Circle(4);
c.garbage = "Oh nooo!"; // Prevent this!!
Any ideas?
EDIT: I was just about to give up on this, but I decided to check to see what the gods do (jQuery dev team).. how do they accomplish this?
$('#Jimbo').hello = "hi!";
alert($('#Jimbo').hello); // undefined
EDIT 2: Stupid mistake.. If you do this:
var hi = $('#Jimbo');
hi.hello = "hi!";
alert(hi.hello); // You get "hi!"
Thanks,
Matt Mueller
No there isn’t. Javascript allows members to be dynamically added and there isn’t a hook to prevent it.