Why does this code run in javascript ? Function inside an object -


when type code in javascript console, not through error, instead runs.

var = {    b:"123",   update(){      console.log("hello");   } } 

the problem is, update() not have function keyword , when check properties of object a , :

b: "123" update: function () __proto__: object 

what javascript doing here?

in ecma script 6, can define properties of object during creation, without :.

for example,

var data = 100; var = { data }; console.log(a); // { data: 100 } 

similarly, in case, creating 2 properties, 1 called b , 1 called update, b 100 , update function object called update.

read more here


note: shorthand notation introduced in ecma script 6. can still use ecma script 5 way of creating properties functions, this

var = {   b: "123",   update: function update() {      console.log("hello");   } } 

Comments

Popular posts from this blog

scala - 'wrong top statement declaration' when using slick in IntelliJ -

c# - DevExpress.Wpf.Grid.InfiniteGridSizeException was unhandled -

PySide and Qt Properties: Connecting signals from Python to QML -