The first question, about associative/integer arrays really applies to almost any programming language where arrays are used. The terminology and syntax do differ but the structure of the two types of arrays are basically identical regardless of the language -
Structure of Associative Array (called an object in javascript):
[
something = athing,
anotherthing = someotherthing
]
javascript syntax:
Code:
var myObject = {something: athing, anotherthing: someotherthing};
or:
Code:
var myObject = {};
myObject.something = athing;
myObject.anotherthing = someotherthing;
There are other ways.
In this type of construct something and anotherthing are often referred to as keys, and athing and someotherthing as items. There is an order to the items, but it is generally unimportant. However, it will always be the order in which they were declared. This can be useful to the clever coder.
Structure of Numerically Indexed Array (called an array in javascript):
[
athing,
someotherthing
]
javascript syntax:
Code:
var myArray = [athing, someotherthing];
or:
Code:
var myArray = [];
myArray[0] = athing;
myArray[1] = someotherthing;
There are other ways.
There are no keys here other than the numerical references which arise simply by the order in which the items are listed or as they are assigned. 0 will always be first and the highest numbered one will always be last regardless of the order in which they were declared.
In javascript you can access the content of the associative array (object) like so:
Code:
alert(myObject.something);
or:
Code:
alert(myObject['something']);
Either of which will alert:
athing
In javascript you can access the content of the numerically indexed array (array) like so:
Which will alert:
athing
In both types, if athing is a string, it will alert that string. If it is not a string, it will type convert it to a string in various ways, depending upon what it is. Alert does this because it can only alert a string. If you use it in a different way - say athing is a function, and you do for associative:
Code:
myObject.something();
or for numerically indexed:
it will execute the athing function.
Now in jQuery the:
Code:
$(document).ready(function() {
// do stuff here
});
Which can also be written other ways, executes not onload, unless the browser has no way jQuery knows about to determine document ready other than onload. In most cases though, jQuery can determine when the page has been parsed by the browser. This is true document ready for the purpose of manipulating the DOM. Images scripts and styles may or may not be loaded yet. If it were onload, all of these should be loaded. This can be crucial in certain cases and you might want to wait until onload for some things. In jQuery onload is:
Code:
$(window).load(function(){
// do stuff here
});
But whichever you use, whatever you do in the:
// do stuff here
section is in a function. Unless it is made accessible to the global scope and/or assigned to/associated with an element on the page, it cannot be accessed outside of that function.
The reason why we can access the selection_replace_with function of:
Code:
arr.editor_content_editor_rte
Is that:
Code:
$('#editor_content_editor_rte').rte({
width: 700,
height: 270,
controls_rte: rte_toolbar,
controls_html: html_toolbar
});
returns an associative array (a javascript object) with the id of the element (editor_content_editor_rte) as the key for this instance. This instance in this case is the full publicly available functionality of this particular editor. When it returned that we assigned it to the global variable:
Anything owned by window is global. So now:
Code:
arr.editor_content_editor_rte.selection_replace_with
is a function on the page and:
Code:
parent.arr.editor_content_editor_rte.selection_replace_with
is a function on the page as accessed from a child of that page.
Bookmarks