Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

javascript code - function in function

Posted on 2014-03-17
3
Medium Priority
?
408 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:
Michael Fowler earned 1200 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 800 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

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Question has a verified solution.

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

Having worked on larger scale sites, we found out that you are bound to look at more scalable solutions to integrating widgets, code snippets or complete applications and mesh them into functional sites, in any given composition. To share some of…
This article discusses how to create an extensible mechanism for linked drop downs.
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…

604 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