Welcome To NaijaSky


Author Javascript Magic  (Read 816 times)

Description:

0 Members and 1 Guest are viewing this topic.

Offline adadis

  • Full Member
  • ***
  • Posts: 230
    • Share Post
Javascript Magic
« on: October 24, 2014, 11:52:43 PM »

Javascript Magic



This tutorial explains closures so that a regular programmer can understand them - using working JavaScript code. It is not for gurus nor functional programmers.
 Closures are not hard to understand once the core concept is grokked. However, they are impossible to understand by reading any academic papers or academically oriented information about them!
 This article is intended for programmers with some programming experience in a main-stream language, and who can read the following JavaScript function
 Most JavaScript programmers will understand how a reference to a function is returned to a variable in the above code. If you don't, then you need to before you can learn closures. A C programmer would think of the function as returning a pointer to a function, and that the variables sayAlert and say2 were each a pointer to a function.
 There is a critical difference between a C pointer to a function, and a JavaScript reference to a function. In JavaScript, you can think of a function reference variable as having both a pointer to a function as well as a hidden pointer to a closure.
 The above code has a closure because the anonymous function function() { alert(text); } is declared inside another function, sayHello2() in this example. In JavaScript, if you use the function keyword inside another function, you are creating a closure.
 In C, and most other common languages after a function returns, all the local variables are no longer accessible because the stack-frame is destroyed.
 In JavaScript, if you declare a function within another function, then the local variables can remain accessible after returning from the function you called. This is demonstrated above, because we call the function say2(); after we have returned from sayHello2(). Notice that the code that we call references the variable text, which was a local variable of the function sayHello2(). $3.00
 Retail Price: $39.00. You Save: $36.00 (92%)
To order with credit/debit card or paypal Click Here
To order with TCurrency/TCredit Click Here
To order with payment into bank Click Here



Become Affiliate and Earn Second Income click here

Linkback: http://naijasky.com/ebooks/2299/javascript-magic/6780/

NaijaSky

Javascript Magic
« on: October 24, 2014, 11:52:43 PM »


Share via facebook Share via linkedin Share via twitter

clip
Autoresponder Magic

Started by adadis

0 Replies
710 Views
Last post October 17, 2014, 03:15:41 PM
by adadis
clip
Affiliate Marketing Magic

Started by adadis

0 Replies
572 Views
Last post October 16, 2014, 05:54:06 PM
by adadis
 
Name: Email:
Verification:
Type the letters shown in the picture
Listen to the letters / Request another image
Type the letters shown in the picture:
Three plus three=sixty or six:
Ten divided by two=five or foul:
First letter of the word MAN is N or M:

Related Topics

  Subject / Started by Replies Last post
0 Replies
477 Views
Last post June 06, 2013, 11:00:04 PM
by oneluv
0 Replies
710 Views
Last post October 17, 2014, 03:15:41 PM
by adadis
0 Replies
177 Views
Last post April 11, 2017, 08:39:23 AM
by naijatown