Username:
Password:
JavaScript Libraries Tutorials

Brief Review / Library Foundations

Subtitles of the Movie

In this tutorial we continue to discuss JavaScript and take a look at the foundations of a lot of the different libraries. Now, these JavaScript Libraries tend to have their foundation in some of the advanced features of the JavaScript language. These include the nature of JavaScript, which is JavaScript is a prototypical language which we'll define in just a moment and then the use of anonymous or in-line functions. Now, of course, there's other, more advanced features that are leveraged by these JavaScript Libraries but these are the two that we're going to discuss here. If you're really interested, you can go in to the documentation of the different JavaScript Libraries and find all that you care to know about how those JavaScript Libraries function. So first of all, let's take a look here at prototypical language. Now, to understand what a prototypical language is, you need to understand the basis of some of our other class-based languages. So in traditional class-based languages, the blueprint or the class is static for all instances or objects created from that class during runtime. This means that Object A will be essentially as Object B if they both share the same class and we can not alter their structure during runtime. And that makes sense because, you know, if you've planned your program appropriately you've taken into consideration all the possible variables that may be affecting your applications, so, you know, there would be no reason to alter the class of an object during runtime. However, prototypical languages allow us to do just that. With prototypical languages, we can manipulate the class of these objects on the fly at runtime. So this essentially means that Object A and Object B can both be manipulated at the same time, even if one was created before the Prototype was manipulated and one was created after the Prototype was manipulated. Thus, we are able to build JavaScript objects as required based on the browser environment that is being used, among other things. Alright. So that might be a little confusing but essentially what it's saying is at all times through the code execution, we have the ability to manipulate the properties, methods and other members of our objects at our own discretion. So if you take a look at this Prototype manipulation example, we have just kind of this simple layout here where we have a script section where it's saying I'm called from before the mists of time and this is our variable before manipulation and because I'm loading in streaming information, this variable is a stream. Then it gets down into the body and we have another script block and here we're manipulating the Prototype. So I reference the string object.Prototype, which basically says modify all strings and give it some functionality. Now, in this case I'm create a function; a function called Self Proclamation. Now, I load into that reference this in-line function, which we'll see again in just a second, where it's doing an alert like this. So essentially what it's going to do is it's going to read the value of the variable and present that in an alert box. The same thing is going to end up happening here with our after manipulation. It's saying hey dude. So when we make the call to self proclamation from both after manipulation and before manipulation, they're both going to have the same behavior, even though the first variable was declared before we made the manipulation. We were able to do that because of the use of Prototype. OK? So it's an extremely powerful concept and that's one of the ways that many of your JavaScript Libraries are able to take care of browser differences as it encounters those browser differences at runtime. Now, next let's go ahead and take a look at our anonymous and in-line functions. Now, anonymous and in-line functions are functions that are defined without a name and typically are used as a callback for an event. These functions allow us to control both scope and lifetime of variables being manipulated inside of our callbacks. Now, as you can see here, we have our example from the previous example where we have an in-line function. So this is setting it up so that when the call to self proclamation is made, it triggers this function block. Now, you're going to want to exercise some discretion for when you're going to be using an anonymous function or you need to turn it into a regular function and that's going to be dependent on how many times you're going to be executing the exact or similar code. So both the prototypical nature of JavaScript and these anonymous in-line functions are used heavily in our JavaScript Libraries.

Tutorial Information

Course: JavaScript Libraries
Author: James Street
SKU: 33984
ISBN: 1-935320-39-4
Release Date: 2009-04-06
Duration: 12.5 hrs / 157 lessons
Work Files: Yes
Captions: Available on CD and Online University
Compatibility: Vista/XP/2000, OS X, Linux
QuickTime 7, Flash 8

VTC Sign up & Benefits

  • Unlimited Access
  • 81,350 Video Tutorials (20,800 free)
  • Video Available as Flash or QuickTime
  • Over 782 Courses
  • $30 for One Month Access
  • Multi-User Discounts Available