开发者

hasOwnProperty and ECMAScript 5 strict mode

开发者 https://www.devze.com 2023-02-03 05:34 出处:网络
I\'m curious: anyone knows why the ECMAScript5 specification hasn\'t tightened more the predefined object prototype\'s properties in strict mode? For instance, it seems like there\'s no info regarding

I'm curious: anyone knows why the ECMAScript5 specification hasn't tightened more the predefined object prototype's properties in strict mode? For instance, it seems like there's no info regarding the way hasOwnProperty is defined. I've tried redefining it (and tested the code in FF4 beta) and I was able to get away with this. If I didn't do anything wrong, then this means that anyone can still rede开发者_JS百科fine the Object.prototype.hasOwnProperty property and really screw all the code that relies on it for working property...

thoughts on this?

EDIT: a little more info as I dig through the spec...

As I've put in a comment below, you can't really change Object.prototype in strict mode due to the metadata that was applied to it (Writable, Enumerable and Configurable are all set to false) and FF 4 beta (which I'm using to run my tests) does generate the exception.

thanks.


And? I can kill of everything on Object.prototype if I wanted to, don't include such code in your project/site, no do something better, find those idiots who are doing such things and make sure to kick'em in the balls.

I mean, I can even screw up any given Python (2.x) program by doing True = False.

You can never protect against idiots. Never. Try to educate or avoid them.

EDIT

To clarify the impossibility of this, if you encapsulate your script into an anonymous wrapper (as you should do if you use it with other code) the "use strict" will be local to your code.

That means, if the evil idiot code does not use strict mode on its own - and they won't... unless they are total idiots, which I'm not talking about here - they run in ES3 and your beautiful strictness doesn't even exist.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号