wlxml: Allow for setting non-function properties via extension
authorAleksander Łukasz <aleksander.lukasz@nowoczesnapolska.org.pl>
Wed, 14 May 2014 13:40:13 +0000 (15:40 +0200)
committerAleksander Łukasz <aleksander.lukasz@nowoczesnapolska.org.pl>
Wed, 28 May 2014 12:45:58 +0000 (14:45 +0200)
src/wlxml/wlxml.js
src/wlxml/wlxml.test.js

index 0505116..bbd6233 100644 (file)
@@ -58,7 +58,9 @@ var installObject = function(instance, klass) {
     });
     instance.object = Object.create(_.extend({}, methods, transformations));
     _.keys(methods).concat(_.keys(transformations)).forEach(function(key) {
     });
     instance.object = Object.create(_.extend({}, methods, transformations));
     _.keys(methods).concat(_.keys(transformations)).forEach(function(key) {
-        instance.object[key] = _.bind(instance.object[key], instance);
+        if(_.isFunction(instance.object[key])) {
+            instance.object[key] = _.bind(instance.object[key], instance);
+        }
     });
 };
 
     });
 };
 
index 9904154..af0e23b 100644 (file)
@@ -286,6 +286,15 @@ describe('WLXMLDocument', function() {
             expect(testClassNode.object.testMethod().sameNode(testClassNode)).to.equal(true, '1');
         });
 
             expect(testClassNode.object.testMethod().sameNode(testClassNode)).to.equal(true, '1');
         });
 
+        it('allows adding non-function properties to an ElementNode of specific class', function() {
+            extension = {wlxmlClass: {test_class: {methods: {
+                testProp: 123
+            }}}};
+            doc.registerExtension(extension);
+            testClassNode = doc.root.contents()[1];
+            expect(testClassNode.object.testProp).to.equal(123);
+        });
+
         it('allows adding transformation to an ElementNode of specific class', function() {
             extension = {wlxmlClass: {test_class: {transformations: {
                 testTransformation: function() { return this; },
         it('allows adding transformation to an ElementNode of specific class', function() {
             extension = {wlxmlClass: {test_class: {transformations: {
                 testTransformation: function() { return this; },