views:

67

answers:

2

In the Javascript, could I define a class, the class itself can also when a function call, similar to the index, such as:

function A()
{
}

var a=new A();
var v=a();       //Use ordinary/like Javascript function use
+1  A: 

This is a abuse of the constructor function syntax (it will work without the new)

function A(message) 
{   
  return function(){alert("Make " + message);}
}

var a = new A("uncertain, divorce the wife say");
var v = a(); //Use ordinary/like Javascript function use
Matthew Flaschen
A +1 only because it works (on FF 3.6 at least). Dreadfully awful though.
pst
A: 

No,This instance "a" has no object "A" prototype

a instanceof A===false

Kuiyou Li