Skip to content

Commit

Permalink
Don't use $n for this.
Browse files Browse the repository at this point in the history
When `this` is guaranteed to be non-null, it's faster to just dereference the
element.
  • Loading branch information
Mike Bostock committed Jul 16, 2010
1 parent a818bbd commit cdac73b
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 16 deletions.
24 changes: 12 additions & 12 deletions nns.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,35 +22,35 @@
N$.prototype = {

add: function(c, s) {
return n$($n(this).insertBefore(
return n$(this.element.insertBefore(
typeof c == "string" ? create(c) : $n(c),
arguments.length == 1 ? null : $n(s)));
},

remove: function(c) {
$n(this).removeChild($n(c));
this.element.removeChild($n(c));
return this;
},

parent: function() {
return n$($n(this).parentNode);
return n$(this.element.parentNode);
},

child: function(i) {
var children = $n(this).childNodes;
var children = this.element.childNodes;
return n$(children[i < 0 ? children.length - i - 1 : i]);
},

previous: function() {
return n$($n(this).previousSibling);
return n$(this.element.previousSibling);
},

next: function() {
return n$($n(this).nextSibling);
return n$(this.element.nextSibling);
},

attr: function(n, v) {
var e = $n(this);
var e = this.element;
n = qualify(n);
if (arguments.length == 1) {
return n.space == null
Expand All @@ -68,28 +68,28 @@
},

style: function(n, v, p) {
var style = $n(this).style;
var style = this.element.style;
if (arguments.length == 1) return style.getPropertyValue(n);
if (v == null) style.removeProperty(n);
else style.setProperty(n, v, arguments.length == 3 ? p : null);
return this;
},

on: function(t, l, c) {
$n(this).addEventListener(t, l, arguments.length == 3 ? c : false);
this.element.addEventListener(t, l, arguments.length == 3 ? c : false);
return this;
},

off: function(t, l, c) {
$n(this).removeEventListener(t, l, arguments.length == 3 ? c : false);
this.element.removeEventListener(t, l, arguments.length == 3 ? c : false);
return this;
},

text: function(v) {
var t = $n(this).firstChild;
var t = this.element.firstChild;
if (!arguments.length) return t && t.nodeValue;
if (t) t.nodeValue = v;
else if (v != null) t = $n(this).appendChild(document.createTextNode(v));
else if (v != null) t = this.element.appendChild(document.createTextNode(v));
return this;
}
}
Expand Down
8 changes: 4 additions & 4 deletions nns.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit cdac73b

Please sign in to comment.