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

前端 未结 5 1851
谎友^
谎友^ 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:48

    you can't reference properties from itself if you are declaring it like that as the properties dont yet exist, you might want to try a different approach

    var time = {};
    time.second = 1000;
    time.minute = time.second * 60;
    ...
    

提交回复
热议问题