473,395 Members | 1,823 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

What is function closure?

?
Jan 27 '08 #1
4 1963
function your_function()
{
var closure='hello function';
return function()
{
alert(cosure);
}
}

On Jan 27, 4:24 pm, LAN MIND <LANMIN...@gmail.comwrote:
?
Jan 27 '08 #2
sorry, that one line should be:
alert(closure);

That should answer your question if it were about how to make a
closure. If your question was actually asking what it was (in a what
does it do sense), then a closure is a function that has access to
various temporary variables that were created in the same scope that
they were (see example below).

On Jan 27, 7:26 pm, "liamge...@gmail.com" <liamge...@gmail.comwrote:
function your_function()
{
var closure='hello function';
return function()
{
alert(cosure);
}

}

On Jan 27, 4:24 pm, LAN MIND <LANMIN...@gmail.comwrote:
?
Jan 27 '08 #3
From the "javascript: The Definitive Guide" book:

«JavaScript functions are a combination of code to be executed and the
scope in which to execute them. This combination of code and scope is
known as a closure (...) All JavaScript functions are closures. These
closures are only interesting, however, in the case discussed above:
when a nested function is exported outside the scope in which it is
defined. When a nested function is used in this way, it is often
explicitly called a closure.»
Jan 27 '08 #4
On Jan 27, 3:01 am, Marcio Faustino <m.faust...@gmail.comwrote:
From the "javascript: The Definitive Guide" book:

«JavaScript functions are a combination of code to be executed and the
scope in which to execute them. This combination of code and scope is
known as a closure (...) All JavaScript functions are closures. These
closures are only interesting, however, in the case discussed above:
when a nested function is exported outside the scope in which it is
defined. When a nested function is used in this way, it is often
explicitly called a closure.»
One common use is when SetTimeout is called. Suppose you set up a
timer which will do something in 10 seconds. You don't have to worry
about keeping the scope around to be used because the closure holds on
to the scope long enough for the SetTimeout to use it.
Jan 27 '08 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
by: Jonas Kölker | last post by:
Hello. I'm doing a Rubik's Cube timer, so I need a function to measure 100ths of a second. I've browsed through the library reference of python.org, but I didn't find anything that struck me as...
4
by: Jack | last post by:
Hello, What function can get a string's long by JavaScript? Thank you
5
by: W. Jack | last post by:
Hello, in VBScript: Int(11.4)=11 What function in JScript like this function? Thank you
2
by: Fred Bassett | last post by:
For example, a database with three tables: EMPLOYEE(employee#, empName, empAddress, empTel) EMPLOYEE_ON_PROJECT(employee#, project#) PROJECT(project#, projectStartDate, projectEndDate) What...
5
by: dubing | last post by:
Hello everyone, There is a field of DATETIME type in our Access 2000 database. PHP is used to query the data and display the query results on the web. Does Access provide any function that can...
3
by: ashok | last post by:
Hi, I need a function that will divide text from mysql in 2 parts, so that I can display first half in one column and second half in second column. I can't find what function will do this job....
12
by: salonowiec | last post by:
My very basic code is: <?php $fname='alpha.ext'; readfile($fname); ?> Only when ext is txt I'm getting a reasonable content, otherwise there's a lot of bush. What function should I use to open...
12
by: Ziggy | last post by:
Hello, What function allows conversion md5 in text? Thanks in advance Thierry
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.