Permalink
Browse files

[lib] handles the displaying of user additions to the prototype

  • Loading branch information...
1 parent 8bccd25 commit a92fd2bf6181f2786c0ae4e55542f23c507d055c Paolo Fragomeni committed May 11, 2012
Showing with 43 additions and 14 deletions.
  1. +27 −14 cdir.js
  2. +16 −0 example/protoype.js
View
41 cdir.js
@@ -126,19 +126,13 @@ if (typeof JSON.decycle !== 'function') {
nu = {};
for (name in value) {
- if (Object.prototype.hasOwnProperty.call(value, name)) {
- nu[name] = derez(value[name],
- path + '[' + JSON.stringify(name) + ']');
- }
+ nu[name] = derez(value[name], path + '[' + JSON.stringify(name) + ']');
}
}
return nu;
- case 'number':
- case 'string':
- case 'boolean':
- case 'undefined':
- case 'function':
+ default:
return value;
+ break;
}
}(object, '[Curcular]'));
@@ -285,7 +279,25 @@ module.exports = function dir (obj, options) {
index: seed
});
- addStrData(node.toString());
+ if (Object.keys(node.prototype).length > 0) {
+
+ indent++;
+ depth++;
+
+ constructMeta(type, depth, node.toString(), ws(indent, true));
+
+ for (var key in node.prototype) {
+ var description = ws(indent, true) + key + ': ';
+ constructMeta(type, depth, node.prototype[key], description);
+ }
+
+ indent--;
+
+ }
+ else {
+ addStrData(node.toString());
+ }
+
break;
case 'array':
@@ -331,6 +343,7 @@ module.exports = function dir (obj, options) {
indent--;
break;
+
}
};
@@ -584,8 +597,6 @@ module.exports = function dir (obj, options) {
//
if (key && searchmode === false) {
-
-
var downAction = (key.name === 'tab' && !key.shift) || key.name === 'down';
var upAction = (key.shift && key.name === 'tab') || key.name === 'up';
@@ -614,12 +625,13 @@ module.exports = function dir (obj, options) {
}
//
- // if this is a toggle, the value must be of type array or object.
+ // if this is a toggle.
//
if ((key.name === 'space' || key.name === 'enter' ||
key.name === 'right' || key.name === 'left') &&
(meta[index].type === 'array' || meta[index].type === 'object' ||
- meta[index].type === 'function' || meta[index].type === 'string')) {
+ meta[index].type === 'function' || meta[index].type === 'string')
+ && selection <= displayed) {
index = map[selection-1];
toggle(index);
@@ -640,6 +652,7 @@ module.exports = function dir (obj, options) {
}
stdin.removeListener('keypress', listener);
+ tty.setRawMode(false);
}
}
View
@@ -0,0 +1,16 @@
+
+console.dir = require('../cdir');
+
+var x = function() {};
+x.prototype.foo = 10;
+x.prototype.bar = [1,2,3];
+x.prototype.bazz = function() { var x = "hello, world"; return x; };
+
+var y = new x();
+
+var foobar = {
+ foodbla: x,
+ foosball: y
+};
+
+console.dir(foobar);

0 comments on commit a92fd2b

Please sign in to comment.