Created
February 9, 2010 17:15
-
-
Save creationix/299423 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
From e71d947e313c63b54a0eba7a9b2c3d85b924aea9 Mon Sep 17 00:00:00 2001 | |
From: Tim Caswell <tim@creationix.com> | |
Date: Tue, 9 Feb 2010 11:15:02 -0600 | |
Subject: [PATCH] Document the changes to sys.inspect's API. It now takes an optional showHidden argument that shows hidden/non-enumerable properties of objects. | |
Also cleanup the lib/sys.js file a bit. | |
--- | |
doc/api.txt | 4 ++-- | |
lib/sys.js | 7 +++---- | |
2 files changed, 5 insertions(+), 6 deletions(-) | |
diff --git a/doc/api.txt b/doc/api.txt | |
index 89995e9..2eeea99 100644 | |
--- a/doc/api.txt | |
+++ b/doc/api.txt | |
@@ -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 | |
diff --git a/lib/sys.js b/lib/sys.js | |
index f39a7cf..461a12c 100644 | |
--- a/lib/sys.js | |
+++ b/lib/sys.js | |
@@ -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'; | |
@@ -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) { | |
@@ -54,6 +53,7 @@ exports.inspect = function (obj, showHidden) { | |
} | |
} | |
+ var base, type, braces; | |
// Determine the object type | |
if (value instanceof Array) { | |
type = 'Array'; | |
@@ -160,4 +160,3 @@ exports.exec = function (command) { | |
*/ | |
exports.inherits = process.inherits; | |
-// Object.create(null, {name: {value: "Tim", enumerable: true}}) | |
\ No newline at end of file | |
-- | |
1.6.5.2 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment