Skip to content

Commit 3aca908

Browse files
creationixry
authored andcommitted
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.
1 parent e33c666 commit 3aca908

File tree

2 files changed

+5
-6
lines changed

2 files changed

+5
-6
lines changed

doc/api.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -208,8 +208,8 @@ Like +puts()+ but without the trailing new-line.
208208
A synchronous output function. Will block the process and
209209
output the string immediately to stdout.
210210

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

214214
+exec(command)+::
215215
Executes the command as a child process, buffers the output and returns it

lib/sys.js

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ exports.error = function (x) {
2626
exports.inspect = function (obj, showHidden) {
2727
var seen = [];
2828
function format(value) {
29-
var keys, visible_keys, base, type, braces;
3029
// Primitive types cannot have properties
3130
switch (typeof value) {
3231
case 'undefined': return 'undefined';
@@ -40,10 +39,10 @@ exports.inspect = function (obj, showHidden) {
4039
}
4140

4241
// Look up the keys of the object.
43-
keys = showHidden ? Object.getOwnPropertyNames(value).map(function (key) {
42+
var keys = showHidden ? Object.getOwnPropertyNames(value).map(function (key) {
4443
return '' + key;
4544
}) : Object.keys(value);
46-
visible_keys = Object.keys(value);
45+
var visible_keys = Object.keys(value);
4746

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

56+
var base, type, braces;
5757
// Determine the object type
5858
if (value instanceof Array) {
5959
type = 'Array';
@@ -160,4 +160,3 @@ exports.exec = function (command) {
160160
*/
161161
exports.inherits = process.inherits;
162162

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

0 commit comments

Comments
 (0)