Attention: We are retiring the ASP.NET Community Blogs. Learn more >

The amazing Javascript

... never ceases to amaze me!

In all ways (including time) this:

var Foos = { One:0, Two:0 } ;

Foos.Speak = function()
{
    return ( this.One + " : " + this.Two ) ;
}

var s = Foos.Speak() + "\n"
    + ( Foos.One + " : " + Foos.Two ) + "\n"
    + ( Foos["One"] + " : " + Foos["Two"] ) ;
	
alert( s ) ;
 
... is the direct equivalent of this: 
function Bars()
{
    this.One = this.Two = 0 ;
}

Bars.prototype.Speak = function()
{
    return ( this.One + " : " + this.Two ) ;
}

bars = new Bars() ;

alert( bars.Speak() ) ;
 
UPDATE: Andy did the research! [ http://weblogs.asp.net/asmith/posts/28643.aspx ]

1 Comment

Comments have been disabled for this content.