Site Archives OOP
JAVASCRIPT: Method overloading
John Resig, one of my heroes and creator of the jQuery JavaScript library, wrote a great piece about overloading methods. He created a dead simple function that shoulders most of the work. Check it out:
1
2
3
4
5
6
7
8
9
function addMethod(object, name, fn){
var old = object[ name ];
object[ name ] = function(){
[...]
JAVASCRIPT: Creating objects and methods
That’s right, object-oriented Javascript. Let’s get to it. We’re going to make an object for storing and retrieving user information.
Let’s start with the base object:
1
2
var User = function(firstName, lastName, emailAddress) {
}
We have to initialize the variables so that they’re available to the rest of the methods of this object:
1
2
3
4
5
var User = function(firstName, lastName, [...]
Find It Quickly
Find what you're looking for quickly by using our keyword search. Can't find it? Try our links below.