Jump to content

Function As Object


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; 

Edited by EricPinxteren
  • Like 1
Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...