TooTallNate / node-time

"time.h" bindings for Node.js
MIT License
382 stars 84 forks source link

Make instance methods non-enumerable #71

Open bminer opened 9 years ago

bminer commented 9 years ago

Constructing a Date like this...

var time = require("time");
var d = new time.Date();

... results in an Object that has a bunch of enumerable instance methods...

{ Mon, 23 Mar 2015 16:16:00 GMT
  getTimezone: [Function: getTimezone],
  getDate: [Function: getDate],
  getDay: [Function: getDay],
  getYear: [Function: getYear],
  getFullYear: [Function: getFullYear],
  getHours: [Function: getHours],
  getMinutes: [Function: getMinutes],
  getMonth: [Function: getMonth],
  getSeconds: [Function: getSeconds],
  getTimezoneOffset: [Function: getTimezoneOffset],
  getTimezoneAbbr: [Function: getTimezoneAbbr],
  setAllDateFields: [Function: setAllDateFields],
  setDate: [Function: setDate],
  setFullYear: [Function: setFullYear],
  setHours: [Function: setHours],
  setMilliseconds: [Function: setMilliseconds],
  setMinutes: [Function: setMinutes],
  setMonth: [Function: setMonth],
  setSeconds: [Function: setSeconds],
  setTime: [Function: setTime],
  setUTCDate: [Function: setUTCDate],
  setUTCFullYear: [Function: setUTCFullYear],
  setUTCHours: [Function: setUTCHours],
  setUTCMilliseconds: [Function: setUTCMillseconds],
  setUTCMinutes: [Function: setUTCMinutes],
  setUTCMonth: [Function: setUTCMonth],
  setUTCSeconds: [Function: setUTCSeconds],
  toDateString: [Function: toDateString],
  toTimeString: [Function: toTimeString],
  toString: [Function: toString],
  toLocaleDateString: [Function: toLocaleDateString],
  toLocaleTimeString: [Function: toLocaleTimeString],
  toLocaleString: [Function: toString] }

This is not very desirable... can Object.defineProperty be used to fix this issue?

bminer commented 9 years ago

I should also mention here that Date.prototype.inspect could be implemented to solve this problem...

See more here: https://nodejs.org/api/util.html#util_custom_inspect_function_on_objects