473,372 Members | 1,049 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,372 software developers and data experts.

What is function closure?

?
Jan 27 '08 #1
4 1962
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
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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...

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.