From: Aleksander Ɓukasz Date: Thu, 5 Dec 2013 12:59:19 +0000 (+0100) Subject: refactoring X-Git-Url: https://git.mdrn.pl/fnpeditor.git/commitdiff_plain/75d2183aafd4b2d3e94c17f6c3c8ee0d8a4738e4?ds=sidebyside;hp=ea72ab1c5af777c4ad75937bda6a5ec6adcd77a3 refactoring --- diff --git a/src/smartxml/smartxml.js b/src/smartxml/smartxml.js index 3ff9df7..bb6258e 100644 --- a/src/smartxml/smartxml.js +++ b/src/smartxml/smartxml.js @@ -580,6 +580,16 @@ var registerTransformation = function(desc, name, target) { target.register(Transformation); }; +var registerMethod = function(methodName, method, target) { + if(target[methodName]) { + throw new Error('Cannot extend {target} with method name {methodName}. Name already exists.' + .replace('{target}', target) + .replace('{methodName}', methodName) + ); + } + target[methodName] = method; +}; + var Document = function(xml) { this.loadXML(xml); @@ -770,21 +780,11 @@ $.extend(Document.prototype, Backbone.Events, { }, registerMethod: function(methodName, method) { - if(this[methodName]) { - throw new Error('Cannot extend document with method name {methodName}. Name already exists.' - .replace('{methodName}', methodName) - ); - } - this[methodName] = method; + registerMethod(methodName, method, this); }, registerNodeMethod: function(methodName, method) { - if(this._nodeMethods[methodName]) { - throw new Error('Cannot extend document with method name {methodName}. Name already exists.' - .replace('{methodName}', methodName) - ); - } - this._nodeMethods[methodName] = method; + registerMethod(methodName, method, this._nodeMethods); }, registerDocumentTransformation: function(desc, name) {