Pencil Media Labs
JavaScript Lab
Javascript Toggling an Element Block or Inine
This content can be toggled.
Photo Slider
Left Position:0
Inheritance
Create a function then a second function that inherits from the original function.
/* Class Person. */
function Person(name) {
this.name = name;
}
Person.prototype.getName = function() {
return this.name;
}
var reader = new Person('John Smith'); reader.getName();
var reader2 = new Person('Jack Tripper'); reader2.getName();
Polymorphism JavaScripting
JavaScript Closures
Two one sentence summaries:
- a closure is the local variables for a function - kept alive after the function has returned, or
- a closure is a stack-frame which is not deallocated when the function returns. (as if a 'stack-frame' were malloc'ed instead of being on the stack!)
function sayHello2(name) {
var text = 'Hello ' + name; // local variable
var sayAlert = function() { alert(text); }
return sayAlert;
}
Closure results here …
