As far as I can tell, JS is function scoped and not block scoped, meaning objects declared inside (parenthesis) do not create a different execution context. However:
$('#firstBtn').click(function first() {
console.log("first activated");
});
$('#secondBtn').click(function() {
console.log("second activated");
first();
});
Returns Reference Error function is undefined
. The function first
is being declared inside a parenthesis, so technically it should be available to other functions that call it from the scope it was declared at.
But this works:
var callDat = $('#firstBtn').click(function first() {
console.log("first activated");
});
$('#secondBtn').click(function() {
console.log("second activated");
callDat.first();
});
My assumption is that since objects are functions, declaring a function inside an object can count as declared inside a different function scope even without curly braces. I however wish for a definitive answer on this.