You need to assign a function to the key like:
var car = {
speed:30,
increaseSpeed: function(milesPerHour) {
return this.speed + milesPerHour;
}
};
Then you can call it like:
car.increaseSpeed(100);
More Related Contents:
- JavaScript code to fetch range of dates from array of objects depending on one attribute of the array using array.reduce()
- How can I do string interpolation in JavaScript?
- How do I check that a number is float or integer?
- Are Javascript arrays sparse?
- How to initialize an array’s length in JavaScript?
- What is the difference between state and props in React?
- How can I set default homepage in FF and Chrome via javascript?
- Sanitizing user input before adding it to the DOM in Javascript
- When do I use parentheses and when do I not?
- Prevent form submission with enter key
- Android WebView JavaScript from assets
- Server Side Calculation using Firebase
- Download Canvas as PNG in fabric.js giving network Error
- Binding vs Arrow-function (in JavaScript, or for react onClick)
- How to get the start and end points of selection in text area?
- Calculate working days between two dates in Javascript excepts holidays
- How to take screen shot of current webpage using Javascript/JQuery?
- Javascript: best Singleton pattern [duplicate]
- How to open specific tab of bootstrap nav tabs on click of a particuler link using jQuery?
- The collection nested inside firebase collection’s model doesn’t have add function
- JS checking deep object property existence [duplicate]
- How can I prevent a click on a ‘#’ link from jumping to top of page?
- jquery/javascript: function(e){…. what is e? why is it needed? what does it actually do/accomplish?
- How to create a custom input type?
- Why does preventDefault on checkbox click event returns true for the checked attribute?
- Testing code that uses an IntersectionObserver
- Check which element has been clicked with jQuery
- Clear a selection in Firefox
- Blob download is not working in IE
- How do I get Greasemonkey to click on a button that only appears after a delay?