Different property value is displayed when JavaScript object is expanded in Chrome console

后端 未结 2 676
不知归路
不知归路 2020-12-02 01:39

I\'m doing some JavaScript debugging with Chrome dev tools and found the following oddity.

How is it possible that date has a different value when the

2条回答
  •  感情败类
    2020-12-02 02:41

    This happens when you define a non enumerable property on an object like this

    Object.defineProperty(res, 'url', { value: '/api/url' });
    

    To fix this you have to make it enumerable like this

    Object.defineProperty(res, 'url', { value: '/api/url', enumerable: true });
    

提交回复
热议问题