javascript - How to imitate moment.js object and change the words printed by console.log?
ringa_lee
ringa_lee 2017-06-26 10:52:46
0
3
941

When I use moment.js, in the environment of Node.js v7

var moment = require('moment');
console.log(moment());

will be printed in the console

moment("2017-06-23T09:06:56.216")

use

console.log(typeof moment());

Learn that moment() is an object

Sometimes, moment.js will also add some prompt words to the console.log, such as when using moment-timezone but not specifying the timezone of the second parameter

console.log(moment.tz('2013-06-01T00:00:00-04:00'));

will be printed on the console

Moment Timezone has no data for 2013-06-01T00:00:00-04:00. See http://momentjs.com
/timezone/docs/#/data-loading/.

moment.utc("2017-06-23T01:12:20.003+00:00")

Above, how to set the text printed by a javascipt object when console.log this object?

ringa_lee
ringa_lee

ringa_lee

reply all(3)
黄舟

Because the inspectmethod

has been rewritten

You can try it under node:

console.log({inspect: function () { return 'this is my value'}})

Or you can try:

moment().inspect() // moment("2017-06-23T09:06:56.216")
typecho

Recommend an article
https://shijianan.com/2017/04...

迷茫

Just override the toString method.

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template