From 0b2942ec56f8015c41a82937a07680028060a0e7 Mon Sep 17 00:00:00 2001 From: Kyle K Date: Mon, 2 Jul 2012 22:26:00 -0500 Subject: learn on events, tweak html --- samples/ref_to_instance.js | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 samples/ref_to_instance.js (limited to 'samples') diff --git a/samples/ref_to_instance.js b/samples/ref_to_instance.js new file mode 100644 index 0000000..975756f --- /dev/null +++ b/samples/ref_to_instance.js @@ -0,0 +1,17 @@ +function foo() { + if ((this instanceof foo) === false) + { + console.log('not an instance, hence a reference!'); + /* returns new object of this class, which will trigger runtime of this + * function */ + return new foo(); + } + else + console.log('you have an instance?'); +} + +var ref = foo; +ref.call(ref); + +var inst = new foo(); + -- cgit v1.2.3