JavaScript prototyping shortest explanation

 
// Without prototyping
 
function Foo() {
    this.do = function(){
    }
}
 
var f1 = new Foo()
var f2 = new Foo()
f1.do == f2.do // FALSE
 
// With prototyping:
 
function Bar(){
}
 
Bar.prototype.do = function(){
}
 
var b1 = new Bar()
var b2 = new Bar()
b1.do == b2.do // TRUE
 

No Comments yet »

RSS feed for comments on this post.

Leave a comment

XHTML: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

*

Powered by WordPress with GimpStyle Theme design by Horacio Bella.
Entries and comments feeds. Valid XHTML and CSS.