top button
Flag Notify
    Connect to us
      Site Registration

Site Registration

How to add function as a property in a JavaScript object?

+1 vote
447 views
How to add function as a property in a JavaScript object?
posted Mar 28, 2014 by Divya Bharti

Share this question
Facebook Share Button Twitter Share Button LinkedIn Share Button

1 Answer

0 votes

The below code will explains how to add function as a property in a JavaScript object

var vehicle = new Object();
vehicle.name = 'swift';
vehicle.color='red';
vehicle.getName = function() 
{ 
return vehicle.name;
}
answer Apr 2, 2014 by Simranjeet Singh
...