How to reference a key from the same object when creating it?

前端 未结 5 1857
谎友^
谎友^ 2021-01-19 15:26

Say I have an object such as this:

var time = {
    \'second\': 1000,
    \'minute\': 1000 * 60,
    \'hour\'  : 1000 * 60 * 60,
    \'day\'   : 1000 * 60 *          


        
5条回答
  •  孤街浪徒
    2021-01-19 15:47

    You can't do this as the object does not exist yet while it's parsed.

    The only way to avoid this is creating an object and then adding the keys one by one - so you already have an object which has the properties you want to re-use.

提交回复
热议问题