Jump to content

Function As Object


Drycodez

Recommended Posts

Mmm.. it does not make much sense. Maybe if you put some prototype function in the function (constructor) like this:

function a(name,age){  this.name = name;  this.age = age;}a.prototype = {   alert:function()   {	   alert(this.name+" is "+this.age+" years old")   },   giveAge:function()  {	 return this.age;  }};var me = new a("eric",25);me.alert();//shows eric is 25 years old 

Then you can make multiple a's, and they have all the same functions. If you just want make object for holding vars, you can als do this:

 //Like this:var a = {name:"eric",age:25}; //or like this: var a = {}; a.name = "eric";a.age	= 25; 

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...