The most powerful keywords of JavaScript
unluckily it is use to hard if you don’t exactly know how it works. If we
execute do something any preparation the keyword is provides to the window
&the function tries to change style. The window doesn’t have object style
the function fails & produce JavaScript error. This is like as reference to
function something (). This keyword is not present in the on click method so it
doesn’t refer to the HTML element.
JavaScript’s
‘this’ Keyword:
Commonly used feature of JavaScript is
the “this”, it is often also one of the most confused any misinterpreted feature
of the language. The “this” keyword is not new those who have programming other
language & more many time then not is provided to the new object create a
class via its constructor. For example if have a class boat(),which has a
method move boat(),when providing to “this” inside of move boat() method, We
are actually accessing the newly created object of boat().In JavaScript we also
have this concept inside a constructor when it is unintentional the ”new”
keyword it is not only the rule and this can many time provide to a different
object from a different execution context. You use the keyword this in the global
context (not inside a function) it always provides to the global object. The
first thing you must realize is that the value of the inside any function is
never static it is always resolute every time you call a function but before
the function executes its code. The value of this inside a function is refers
to the parent scope in which the function called? & more importantly how
the actual function syntax was written?
A function is called we must look at the
nearest left side of the brackets or” ()”.if one the left side of the () we can
see a reference, then the value of this boat passed to the function call is
exactly of the object belongs to, otherwise it is global object.
0 comments:
Post a Comment