Solved

javascript code - function in function

Posted on 2014-03-17
3
377 Views
Last Modified: 2014-03-19
i am trying to understand this code-
in this code, a function is written inside a function -

   <script>
 
      require([
        "esri/map", "esri/layers/ArcGISTiledMapServiceLayer", 
        "esri/domUtils", "esri/request",
        "dojo/parser", "dojo/number", "dojo/json", "dojo/dom", 
        "dijit/registry", "modules/RasterLayer",

        "dijit/layout/BorderContainer", "dijit/layout/ContentPane", 
        "dijit/form/HorizontalSlider", "dojo/domReady!"
      ], function(
        Map, ArcGISTiledMapServiceLayer, 
        domUtils, esriRequest,
        parser, number, JSON, dom, 
        registry, RasterLayer
      ) {

        //some code 
        function mapLoaded() {
//code of maploaded
        }

        function getRasterData() {
       //code 
        }

        function setElevation() {
        //code 
         }
 
         function supports_canvas() {
                //code 
         }
      });
    </script>

Open in new window


Why the functions "setElevation()", "supports_canvas()", "getRasterData() ",  "mapLoaded()"  
are written within

 "function(
        Map, ArcGISTiledMapServiceLayer,
        domUtils, esriRequest,
        parser, number, JSON, dom,
        registry, RasterLayer
      ) "

 thanks so much

pl guide
0
Comment
Question by:ts84zs
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 23

Accepted Solution

by:
Michael74 earned 300 total points
ID: 39936069
It is called closure.

Have a look at these links for more info
http://web.archive.org/web/20120101221030/http://blog.morrisjohns.com/javascript_closures_for_dummies.html
http://javascriptissexy.com/understand-javascript-closures-with-ease/

A closure is an inner function that has access to the outer (enclosing) function’s variables—scope chain. The closure has three scope chains: it has access to its own scope (variables defined between its curly brackets), it has access to the outer function’s variables, and it has access to the global variables.

The inner function has access not only to the outer function’s variables, but also to the outer function’s parameters. Note that the inner function cannot call the outer function’s arguments object, however, even though it can call the outer function’s parameters directly.
0
 
LVL 29

Assisted Solution

by:Pravin Asar
Pravin Asar earned 200 total points
ID: 39937416
Having a the function inside a function, is a style some developers used to build functions which work similar to methods in purely objected-oriented code.

This style of code is good for building custom objects.
(see http://www.w3schools.com/js/js_obj_intro.asp)

JavaScript is a Object-oriented language. If you want to learn more about this ,
please visit

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Introduction_to_Object-Oriented_JavaScript
0
 

Author Comment

by:ts84zs
ID: 39937572
thanks so much

actually i do not understand the whole code ,,,  I will open another question to explain the whole code....
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
jQuery Datatables.js Selecting a Row to get ID 5 37
ASP sending two datas 2 23
Timer on div 5 24
javascript form submition 2 22
Article by: DanRollins
This article describes a JavaScript program that creates a maze made of hexagonal cells.  In Part 2 (http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/A_7850-Hex-Maze-Part-2.html), we'll extend the program by adding a depth-…
This article will give core knowledge of JavaScript and will head in to your first JavaScript program. I am Durvesh Naik and I am here to deal with this series of JavaScript. I will teach you JavaScript in part wise , as its quite boring to read big…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

733 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question