Skip to content

Commit

Permalink
Document the changes to sys.inspect's API.
Browse files Browse the repository at this point in the history
It now takes an optional showHidden argument that shows hidden/non-enumerable properties of objects.

Also cleanup the lib/sys.js file a bit.
  • Loading branch information
creationix authored and ry committed Feb 9, 2010
1 parent e33c666 commit 3aca908
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 6 deletions.
4 changes: 2 additions & 2 deletions doc/api.txt
Expand Up @@ -208,8 +208,8 @@ Like +puts()+ but without the trailing new-line.
A synchronous output function. Will block the process and
output the string immediately to stdout.

+inspect(object)+ ::
Return a string representation of the +object+. (For debugging.)
+inspect(object, showHidden)+ ::
Return a string representation of the +object+. (For debugging.) If showHidden is true, then the object's non-enumerable properties will be shown too.

+exec(command)+::
Executes the command as a child process, buffers the output and returns it
Expand Down
7 changes: 3 additions & 4 deletions lib/sys.js
Expand Up @@ -26,7 +26,6 @@ exports.error = function (x) {
exports.inspect = function (obj, showHidden) {
var seen = [];
function format(value) {
var keys, visible_keys, base, type, braces;
// Primitive types cannot have properties
switch (typeof value) {
case 'undefined': return 'undefined';
Expand All @@ -40,10 +39,10 @@ exports.inspect = function (obj, showHidden) {
}

// Look up the keys of the object.
keys = showHidden ? Object.getOwnPropertyNames(value).map(function (key) {
var keys = showHidden ? Object.getOwnPropertyNames(value).map(function (key) {
return '' + key;
}) : Object.keys(value);
visible_keys = Object.keys(value);
var visible_keys = Object.keys(value);

// Functions without properties can be shortcutted.
if (typeof value === 'function' && keys.length === 0) {
Expand All @@ -54,6 +53,7 @@ exports.inspect = function (obj, showHidden) {
}
}

var base, type, braces;
// Determine the object type
if (value instanceof Array) {
type = 'Array';
Expand Down Expand Up @@ -160,4 +160,3 @@ exports.exec = function (command) {
*/
exports.inherits = process.inherits;

// Object.create(null, {name: {value: "Tim", enumerable: true}})

0 comments on commit 3aca908

Please sign in to comment.