Forums

The forums ran from 2008-2020 and are now closed and viewable here as an archive.

Home Forums JavaScript Learning jQuery…Have a few questions Re: Learning jQuery…Have a few questions

#141693
pixelgrid
Participant

question #1
a and b are generally the same but the second one has to be defined before it gets called the first one can be called before declaring it
so

one();
function one(){
console.log(‘yes’);
}
//will log yes

two();
var two = function(){
console.log(‘no’);
}
typeerror two is not a function

in general the second case is used in objects when you want a method handler

Question #1 three you are declaring a function to the jquery prototype so you can use it with a jquery constructor

$(‘.my_selector’).my_custom_function();

question 2

the first one is a shorthand of the second one they are the same