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; }