You could make var3 a function, and calling it will allow you to use ‘this’:
x= {
v1:4,
v2:5,
v3:function(){return this.v1 + this.v2;}
};
alert(x.v3());
More Related Contents:
- JavaScript property access: dot notation vs. brackets?
- Self-references in object literals / initializers
- How to use a variable for a key in a JavaScript object literal?
- How can I add a key/value pair to a JavaScript object?
- dynamic keys for object literals in Javascript [duplicate]
- Template String As Object Property Name
- Adding/removing items from a JavaScript object with jQuery
- Arrow Function in Object Literal [duplicate]
- Use a concatenated (dynamic) string as JavaScript object key? [duplicate]
- create object using variables for property name [duplicate]
- Adding Prototype to JavaScript Object Literal
- How to create an array of object literals in a loop?
- JavaScript object literal length === undefined?
- JavaScript – Advantages of object literals
- Safely parsing a JSON string with unquoted keys
- Dynamically Add Variable Name Value Pairs to JSON Object
- When should I use double or single quotes in JavaScript?
- How to convert a Date to UTC?
- Download a file from NodeJS Server using Express
- jQuery ajax success callback function definition
- Spread Syntax vs Rest Parameter in ES2015 / ES6
- What happens when using this.setState multiple times in React component?
- Can’t set innerHTML on tbody in IE
- Questions on Javascript hoisting
- Ajax, prevent multiple request on click
- ‘observe’ on ‘MutationObserver’: parameter 1 is not of type ‘Node’
- What is a TransientTransactionError in Mongoose (or MongoDB)?
- size of createElement(“svg”) is 0,0
- How to generate and prompt to save a file from content in the client browser? [duplicate]
- Get data from html and and pass the data back to the front end using ajax or js