A
Asen Bozhilov
Dmitry said:If you still wanna to write this as a rule, please mentioned, that
it's not the rule, but *just your own suggestion and own meaning*,
meanwhile other people can choose different (good) way augmenting
object and write in OOP-style such as `string.capitalize()' instead of
long ugly `Ext.util.Format.capitalize(string)'. Especially in own
project.
You are absolutely right, but augmentation Object.prototype can be
harmful and confused. If implementations use native object produced
via `new Object()` as a VO and internal [[Prototype]] refer
Object.prototype, any augmentation of `object' referred from
Object.prototype can be harmful and confused. See below:
Object.prototype.x = 10;
var x = null;
(function()
{
window.alert(x);
}());
Expected value of `x` is `null`, but if VO is implement as a native
object value of `x` will be 10. Because:
| 10.1.4 Scope Chain and Identifier Resolution
| 1. Get the next object in the scope chain.
| If there isn't one, go to step 5.
In that case next object is VO/AO associated with EC created from
anonymous function.
| 2. Call the [[HasProperty]] method of Result(1),
| passing the Identifier as the property.
[[HasProperty]] lookup in prototype chain and will be return `true` in
that case.
| 3. If Result(2) is true, return a value of type Reference
| whose base object is Result(1) and whose property name
| is the Identifier.
{base : VO, propertyName : x};
So in my case *expected* value is primitive number value 10.
See and next example in Firefox 3.5:
Object.prototype.x = 10;
(function()
{
window.alert(x); //10 expected ReferenceError
}());
window.alert(this instanceof Object); //false
window.alert(this.__proto__ === Object.prototype); //false
How it is implement Global Object in Firefox 3.5? We can see Global
Object does not refer from internal [[Prototype]] object referred from
Object.prototype. And we can see that `object' doesn't inherit in
explicit way from Object.prototype. The question is, how it is
implement that object?
Regards.