| 1 |
"use strict"; |
| 2 |
module.exports = Leaf; |
| 3 |
|
| 4 |
var Node = require('./Node'); |
| 5 |
var NodeList = require('./NodeList'); |
| 6 |
var utils = require('./utils'); |
| 7 |
var HierarchyRequestError = utils.HierarchyRequestError; |
| 8 |
var NotFoundError = utils.NotFoundError; |
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
function Leaf() { |
| 13 |
Node.call(this); |
| 14 |
} |
| 15 |
|
| 16 |
Leaf.prototype = Object.create(Node.prototype, { |
| 17 |
hasChildNodes: { value: function() { return false; }}, |
| 18 |
firstChild: { value: null }, |
| 19 |
lastChild: { value: null }, |
| 20 |
insertBefore: { value: function(node, child) { |
| 21 |
if (!node.nodeType) throw new TypeError('not a node'); |
| 22 |
HierarchyRequestError(); |
| 23 |
}}, |
| 24 |
replaceChild: { value: function(node, child) { |
| 25 |
if (!node.nodeType) throw new TypeError('not a node'); |
| 26 |
HierarchyRequestError(); |
| 27 |
}}, |
| 28 |
removeChild: { value: function(node) { |
| 29 |
if (!node.nodeType) throw new TypeError('not a node'); |
| 30 |
NotFoundError(); |
| 31 |
}}, |
| 32 |
removeChildren: { value: function() { }}, |
| 33 |
childNodes: { get: function() { |
| 34 |
if (!this._childNodes) this._childNodes = new NodeList(); |
| 35 |
return this._childNodes; |
| 36 |
}} |
| 37 |
}); |