javascript - Something I don't understand about 'use strict' and this -
as far know, declare in javascript, belongs global object (unless declare inside of object, object belong window object, , whatever declare inside of it, object), so, inside of browser environment, global object window
.
say declare: var x = 'hi'
this accessed with:
x
or
window.x
and both absolutely same, right? why, 'use strict'
, when returning this
'global' variable, can window
object if specify said function belongs window
?
function fun() { 'use strict'; return this; } fun(); // undefined window.fun(); // window object // aren't both absolutely same?
also, why function return undefined
, if function supposed belong obj
?
obj = { method: function () { 'use strict'; function yeah() { // doesn't belong obj? return this; // doesn't seem 'yeah' } // belongs window. return yeah(); } };
thanks.
so why, 'use strict', when returning 'global' variable, can window object if specify said function belongs window?
you can window
object accessing window
.
it won't value of this
because feature made easy accidentally write insecure code , came performance cost.
not automatic boxing performance cost, exposing global object in browsers security hazard, because global object provides access functionality "secure" javascript environments must restrict. strict mode function, specified not boxed object, , if unspecified, undefined
also, why function return undefined, if function supposed belong obj?
while yeah
in scope of function method of obj
, yeah
isn't method of obj
aren't calling one.
i.e. because calling yeah()
, not obj.yeah()
(or yeah.call(obg)
etc).
that has nothing "use strict"
though.
Comments
Post a Comment