From 11f91616011da9a34a7d3ad4e058a929686c34ef Mon Sep 17 00:00:00 2001 From: Daniel-dlev1 Date: Sun, 23 Mar 2014 20:38:21 -0400 Subject: [PATCH 1/4] Absence of "new" works in more cases. Since a class can be inside an object, when you instantiate that class without "new", the "this" context in the constructor points to that object, instead of the global context. --- classy.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/classy.js b/classy.js index 9ca6051..c817d8c 100644 --- a/classy.js +++ b/classy.js @@ -122,7 +122,7 @@ var rv = function() { if (disable_constructor) return; - var proper_this = context === this ? cheapNew(arguments.callee) : this; + var proper_this = this instanceof arguments.callee ? this : cheapNew(arguments.callee); if (proper_this.__init__) proper_this.__init__.apply(proper_this, arguments); proper_this.$class = rv; @@ -158,4 +158,4 @@ /* export the class */ return Class; -}); \ No newline at end of file +}); From c63853907d08faec8d8d0b91e199c52f61603d3b Mon Sep 17 00:00:00 2001 From: Daniel-dlev1 Date: Thu, 1 May 2014 14:36:16 -0400 Subject: [PATCH 2/4] use strict --- classy.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/classy.js b/classy.js index c817d8c..c2e3b80 100644 --- a/classy.js +++ b/classy.js @@ -8,7 +8,7 @@ if (typeof module != 'undefined' && module.exports) module.exports = definition() else if (typeof define == 'function' && typeof define.amd == 'object') define(definition) else this.Class = definition() -}(function (undefined) { +}(function (undefined) { 'use strict'; var CLASSY_VERSION = '1.4', context = this, @@ -122,7 +122,7 @@ var rv = function() { if (disable_constructor) return; - var proper_this = this instanceof arguments.callee ? this : cheapNew(arguments.callee); + var proper_this = this instanceof rv ? this : cheapNew(rv); if (proper_this.__init__) proper_this.__init__.apply(proper_this, arguments); proper_this.$class = rv; From e4ef135b38b9f779e5f0dd7cbebae775ff3c3130 Mon Sep 17 00:00:00 2001 From: Daniel-dlev1 Date: Thu, 1 May 2014 16:15:22 -0400 Subject: [PATCH 3/4] strict mode --- classy.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/classy.js b/classy.js index c2e3b80..9ef6c35 100644 --- a/classy.js +++ b/classy.js @@ -4,14 +4,14 @@ * :copyright: (c) 2011 by Armin Ronacher. * :license: BSD. */ +!function (context) { !function (definition) { if (typeof module != 'undefined' && module.exports) module.exports = definition() else if (typeof define == 'function' && typeof define.amd == 'object') define(definition) - else this.Class = definition() + else context.Class = definition() }(function (undefined) { 'use strict'; var CLASSY_VERSION = '1.4', - context = this, old = context.Class, disable_constructor = false; @@ -159,3 +159,4 @@ /* export the class */ return Class; }); +}(this); From 23c7e4eea59198d42c936d16d53ae3891e223901 Mon Sep 17 00:00:00 2001 From: Daniel-dlev1 Date: Thu, 1 May 2014 16:16:31 -0400 Subject: [PATCH 4/4] strict mode 2 --- classy.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/classy.js b/classy.js index 9ef6c35..10402c9 100644 --- a/classy.js +++ b/classy.js @@ -5,11 +5,12 @@ * :license: BSD. */ !function (context) { +'use strict'; !function (definition) { if (typeof module != 'undefined' && module.exports) module.exports = definition() else if (typeof define == 'function' && typeof define.amd == 'object') define(definition) else context.Class = definition() -}(function (undefined) { 'use strict'; +}(function (undefined) { var CLASSY_VERSION = '1.4', old = context.Class,