Question: JavaScript Problems #30 . Modify the Club function again: Add a property to this called add. The value of add will be a function. This

JavaScript Problems

#30 .

Modify the Club function again: Add a property to "this" called "add". The value of "add" will be a function. This function will take a name passed to it and add that name to the members list of the club. The function can't directly refer to whatever variable you store the new Club it must use this. The function should return the Club object when it is done. Finally, run this code to get the required output: var c = new Club("computer"); c.add("john"); c.add( "fred" ); console.log( c.members );

How do you assign a function to a variable? All functions are objects. You can refer to them by name, just don't put () on the right side of the name - because that will call the function. So you can copy function objects to anywhere you wish. You can also create a function without a name, called an anonymous function - in which case, you must assign it to a variable when you create it otherwise you'll never be able to use it (because it has no name to refer to.)

Club function - please use this and modify:

function Club(name) { this.name = name; this.members = []; }

var club = new Club('computer');

club.members.push('john'); club.members.push('fred');

console.log(club);

After Modify the Club function again, output:

JavaScript Problems #30 . Modify the Club function again: Add a property

#31.

If your add function / method works properly and returns it's object when done - you can now do something like this: console.log( (new Club("computer")).add("john").add("fred").members )

console.log) ["john", "fred

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!