ShowUsYour<Blog>

Irregular expressions regularly

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 ]

Comments

TrackBack said:

# September 22, 2003 1:07 AM

TrackBack said:

# September 22, 2003 4:02 PM

Ricardo said:

The first alerts 3 lines of values, the 2nd just one line, so they are not exactly equivalent.

# May 7, 2008 1:30 PM
Leave a Comment

(required) 

(required) 

(optional)

(required)