DOM events bubble up through the DOM tree and register against every element up to the top. The object passed to the listener (call it e
for example) will have the e.target
property, which was the element that was interacted with directly ("clicked", etc.) and the e.currentTarget
property, which is the element that was listening when this event listener caught the event.
e.stopPropagation()
will keep the event from continuing to bubble up the DOM tree.
Starts off global. Inside function definitions, it's undefined unless it's been set by other methods (see below).
- In object methods like
myObject.doSomething()
,this
will be set tomyObject
. - Use
fn.call(context)
,fn.apply(context)
, orfn.bind(context)
to deliberately set the value ofthis
P much everything has a prototype, kinda like a parent. If you call for a property using me.property
or me.function()
, JS will look at me and all of my prototype parents to see if that property/function exists and use the first one it finds.
AMD uses define()
and looks very async, while CommonJS uses just the require()
method and looks incredibly sync.
// AMD
define('mymodule', ['dep1', 'dep2', 'dep3'], function (dep1, dep2, dep3) {
// module definition
});
// CommonJS
var dep1 = require("dep1");
var dep2 = require("dep2");
var dep3 = require("dep3");
module.exports = function () {
// module definition
};
For AMD, think requireJS and for CommonJS think of how Node.js works.
You have access to the variables in your current function and everything up from there, but if you use one function to create another, and the resulting function had access to variables at its creation, it will always have access to those variables for its whole life.