dom-text.js 720 B

123456789101112131415161718192021222324252627
  1. module.exports = DOMText
  2. function DOMText(value, owner) {
  3. if (!(this instanceof DOMText)) {
  4. return new DOMText(value)
  5. }
  6. this.data = value || ""
  7. this.length = this.data.length
  8. this.ownerDocument = owner || null
  9. }
  10. DOMText.prototype.type = "DOMTextNode"
  11. DOMText.prototype.nodeType = 3
  12. DOMText.prototype.nodeName = "#text"
  13. DOMText.prototype.toString = function _Text_toString() {
  14. return this.data
  15. }
  16. DOMText.prototype.replaceData = function replaceData(index, length, value) {
  17. var current = this.data
  18. var left = current.substring(0, index)
  19. var right = current.substring(index + length, current.length)
  20. this.data = left + value + right
  21. this.length = this.data.length
  22. }