I'm writing a jQuery plugin, which similar to this,
$(this).each(function(){
$el = $(this).find('.el')
$el.click(function(){
test();
});
function test() {
console.log('test init');
}
});
This works fine when $el is clicked
but when i use the test() outside of $el.click like this
$(this).each(function(){
$el = $(this).find('.el')
test();
function test() {
console.log('test init');
}
});
I get type error undefined is not a function
PS: I'm coding in coffee, syntax/spelling isn't an issue here
test()isn't defined yet when it is called? JS executes lineraly, which is like "top-to-bottom". try moving test below the declaration, and tell me if it works.