-
-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
James Halliday
committed
Jul 9, 2010
1 parent
c3266e0
commit 607de69
Showing
1 changed file
with
25 additions
and
0 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
#!/usr/bin/env node | ||
var sys = require('sys'); | ||
var Traverse = require('traverse').Traverse; | ||
|
||
var id = 54; | ||
var callbacks = {}; | ||
var obj = { moo : function () {}, foo : [2,3,4, function () {}] }; | ||
|
||
var scrubbed = Traverse(obj).modify(function (x) { | ||
if (x instanceof Function) { | ||
callbacks[id] = { id : id, f : x, path : this.path }; | ||
this.update('[Function]'); | ||
id++; | ||
} | ||
}).get(); | ||
|
||
sys.puts(JSON.stringify(scrubbed)); | ||
sys.puts(sys.inspect(callbacks)); | ||
|
||
/* Output: | ||
{"moo":"[Function]","foo":[2,3,4,"[Function]"]} | ||
{ '54': { id: 54, f: [Function], path: [ 'moo' ] } | ||
, '55': { id: 55, f: [Function], path: [ 'foo', '3' ] } | ||
} | ||
*/ |