Welcome Guest, Not a member yet? Register   Sign In
functions within function?
#1

Saw this example on the web. What's the purpose of the two functions being contained in a function? Why would someone put that top line in there? The two functions should work without it I would think.

Code:
$(function () {
  $("div.class").click(function(){
    //Doo something

  });

  $("div.secondclass").click(function(){
    //Doo something
  });

});
Reply
#2

It's an anonymous function: https://en.wikibooks.org/wiki/JavaScript..._Functions

Usually used (in JS) to execute something upon page load.
Reply
Reply
#4

(This post was last modified: 07-17-2015, 10:13 AM by Blair2004.)

hi,
those are anonymous... and for the most of the time are used to group feature together...

It's just like Hooks in PHP https://github.com/Blair2004/tendoo-cms/...Events.php, which can be used with anonymous function.
NexoPOS 2.6.2 available on CodeCanyon.
Reply




Theme © iAndrew 2016 - Forum software by © MyBB