tobie (owner)

Revisions

gist: 81118 Download_button fork
public
Description:
SpiderMonkey's uneval for common types
Public Clone URL: git://gist.github.com/81118.git
Embed All Files: show embed
JavaScript #
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
function repr(v) {
  print(uneval(v))
}
 
repr(false)
//-> false
 
repr(true)
//-> true
 
repr(null)
//-> null
 
repr(undefined)
//-> (void 0)
 
repr('foo')
//-> "foo"
 
repr(123)
//-> 123
 
repr(123.4)
//-> 123.4
 
r = new RegExp('foo')
repr(r)
//-> /foo/
 
repr(new Date)
//-> (new Date(1237141453430))
 
repr([0, 1, [2, 3]])
//-> [0, 1, [2, 3]]
 
repr({foo: 123})
//-> ({foo:123})
 
a = [1, 2, 3]
a.push(a)
repr(a)
//-> #1=[1, 2, 3, #1#]
 
h = {foo: 123}
h.bar = h
repr(h)
//-> #1={foo:123, bar:#1#}
 
function Foo() {
var self = {}
self.__init__ = function () {
  self.foo = 123
  self.bar = 456
}
return self
}
repr(Foo())
//-> ({__init__:(function () {self.foo = 123;self.bar = 456;})})
 
repr(Foo)
//-> function Foo() {var self = {};self.__init__ = function () {self.foo = 123;self.bar = 456;};return self;}
 
repr([].reverse)
//-> function reverse() {[native code]}