From e82be3aafa2d35d6cacaff36fc3e44f1e9e59ae7 Mon Sep 17 00:00:00 2001 From: rma4ok Date: Thu, 24 Jan 2013 19:09:54 -0500 Subject: [PATCH] [refactor] better aware of forgetting `new` --- lib/metamorph.js | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/lib/metamorph.js b/lib/metamorph.js index 4e97f97..9392d68 100644 --- a/lib/metamorph.js +++ b/lib/metamorph.js @@ -5,8 +5,7 @@ (function(window) { - var K = function(){}, - guid = 0, + var guid = 0, document = window.document, // Feature-detect the W3C range API, the extended check is for IE9 which only partially supports ranges @@ -39,12 +38,10 @@ // Takes a string of HTML as the argument. var Metamorph = function(html) { - var self; + var self = this; - if (this instanceof Metamorph) { - self = this; - } else { - self = new K(); + if (!(self instanceof Metamorph)) { + return new Metamorph(html); } self.innerHTML = html; @@ -55,8 +52,6 @@ return self; }; - K.prototype = Metamorph.prototype; - var rangeFor, htmlFunc, removeFunc, outerHTMLFunc, appendToFunc, afterFunc, prependFunc, startTagFunc, endTagFunc; outerHTMLFunc = function() {