jQuery in Action

328
APPENDIX
JavaScript that you need to know but might not!
When we declare a top-level named function, a
Function
instance is created
and assigned to a property of
window
that's automatically created using the so-
called function name. The
Function
instance itself no more has a name than a
Number
literal or a
String
literal. Figure A.2 illustrates this concept.
Remember that, when a top-level variable is created in an
HTML
page, the vari-
able is created as a property of the
window
instance. Therefore, the following state-
ments are all equivalent:
function hello(){ alert('Hi there!'); }
hello = function(){ alert('Hi there!'); }
window.hello = function(){ alert('Hi there!'); }
Although this may seem like syntactic juggling, it's important to understanding
that
Function
instances are values that can be assigned to variables, properties, or
parameters just like instances of other object types. And like those other object
types, nameless disembodied instances aren't of any use unless they're assigned to
a variable, property, or parameter through which they can be referenced.
We've seen examples of assigning functions to variables and properties, but what
about passing functions as parameters? Let's take a look at why and how we do that.
Gecko browsers and function names
Browsers based on the Gecko layout engine, such as Firefox and Camino, store the
name of functions defined using the top-level syntax in a nonstandard property of
the function instance named name. Although this may not be of much use to the
general development public, particularly considering its confinement to Gecko-
based browsers, it's of great value to writers of browser plugins and debuggers.
Figure A.2 A Function instance is a nameless object like the Number 213 or any other
JavaScript value. It's named only by references that are made to it.


Другие страницы

 
Cкачать книги бесплатно без регистрации в электронном виде (pdf, chm, txt).Вы можете читать книги онлайн на нашем сайте литературного портала книг.Большая подборка учебников, пособий, интересных книг.Электронные книги на английском языке скачать бесплатно без смс.