where it’s declared. • Go locate where a function is called from, not always easy, some coding patterns obscure this. • Think always on the call-stack, THINK OF THE CALL- STACK. • Call-stack: Stack of functions that have been called. • Call-site we care about is IN the invocation BEFORE the currently executing function.
• foo is declared then assigned to obj • foo is owned/contained by obj • this.a is a synonym of obj.a == implicit binding. function foo() { console.log( this.a ); } ! var obj = { a: 2, foo: foo }; ! obj.foo(); // 2
• It goes back to the default binding. • It references to the global object or to undefined depending on strict mode. • Call-site is what matters. • bar() undecorated call == default binding. function foo() { console.log( this.a ); } ! var obj = { a: 2, foo: foo }; ! var bar = obj.foo; var a = "oops, global"; ! bar();
This method shall return a true value if any of the elements in the array satisfies the given predicate. • If the spec is a function then it shall be called for each element in the array, whenever the spec function returns a true value then immediately the any function will success (return a true value), but if it doesn’t for any of the collection elements then the any function will fail (return false value). • If the spec parameter is not a function object, then it will be tested against each element of the array and it will success if any elements matches the spec parameter value.
something like this: people.where(function(dev){ return !dev.skills.any(function(skill) { return skill == 'PHP' }); }) .each(logPerson) Or you could do this: people.where(function(dev){ return !dev.skills.any('PHP'); }) .each(logPerson)
‘All’ functions have methods via their Prototype. We’ are interested in ‘CALL’ and ‘APPLY’ function foo() { console.log( this.a ); } ! var obj = { a: 2 }; ! foo.call( obj ); // 2 • If we pass a primitive as first param, it will be wrapped in its object form. Formerly known as ‘Boxing’