[Pkg-javascript-commits] [ltx] 362/469: Close attrs object arguement.

Jonas Smedegaard dr at jones.dk
Wed Aug 31 13:03:26 UTC 2016


This is an automated email from the git hooks/post-receive script.

js pushed a commit to branch master
in repository ltx.

commit 47284d2ce1427e77488a7ad00ce701b20603e85b
Author: Lloyd Watkin <lloyd.watkin at surevine.com>
Date:   Wed Dec 10 15:33:10 2014 +0000

    Close attrs object arguement.
    
    Closes #50 from @sonnyp
---
 lib/element.js       | 15 ++++++---------
 test/element-test.js |  2 +-
 2 files changed, 7 insertions(+), 10 deletions(-)

diff --git a/lib/element.js b/lib/element.js
index befaccd..a5f54e5 100644
--- a/lib/element.js
+++ b/lib/element.js
@@ -10,7 +10,7 @@ function Element(name, attrs) {
     this.name = name
     this.parent = null
     this.children = []
-    this.setAttrs(attrs);
+    this.setAttrs(attrs)
 }
 
 /*** Accessors ***/
@@ -83,13 +83,10 @@ Element.prototype.getXmlns = function() {
 
 Element.prototype.setAttrs = function(attrs) {
     this.attrs = {}
-    if (attrs) {
-        for (var i in attrs) {
-            if (attrs.hasOwnProperty(i))
-                this.attrs[i] = attrs[i]
-        }
-    }
-};
+    Object.keys(attrs || {}).forEach(function(key) {
+        this.attrs[key] = attrs[key]
+    }, this)
+}
 
 /**
  * xmlns can be null, returns the matching attribute.
@@ -313,7 +310,7 @@ Element.prototype.toJSON = function() {
         name: this.name,
         attrs: this.attrs,
         children: this.children.map(function(child) {
-            return child && child.toJSON ? child.toJSON() : child;
+            return child && child.toJSON ? child.toJSON() : child
         })
     }
 }
diff --git a/test/element-test.js b/test/element-test.js
index cfc74f9..cfe33a4 100644
--- a/test/element-test.js
+++ b/test/element-test.js
@@ -7,7 +7,7 @@ var vows = require('vows')
 vows.describe('ltx').addBatch({
     'new element': {
         'doesn\'t reference original attrs object': function() {
-            var o = {'foo': 'bar'}
+            var o = { foo: 'bar' }
             var e = new ltx.Element('e', o)
             assert.notEqual(e.attrs, o)
             e.attrs.bar = 'foo'

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-javascript/ltx.git



More information about the Pkg-javascript-commits mailing list