Talk:UnityScript versus JavaScript

From Unify Community Wiki
Jump to: navigation, search

The this keyword

In JavaScript, this can refer to one of two things, depending on the context: The global object (best not explained here) The object to which the current method or constructor belongs

In Javascript, a function doesn't always have to take global scope. There are many cases where, for instance, an event callback takes the scope of the object that triggered the callback. Case in point, most (if not all) DOM events will take on the context of the DOM element triggering it -- such as a callback for the onclick event will take the context of the DOM clicked. Another example is with AJAX callbacks taking the context of the XHR object. In both cases, neither take the context of global object (in browser Javascript, that's window).

I know I'm being a little pedantic, but I get bothered when I see incorrect info posted somewhere.

Personal tools
Namespaces

Variants
Actions
Navigation
Extras
Toolbox