From c78adda6fbe8bcaab2d390c83359e5877145173a Mon Sep 17 00:00:00 2001 From: Ruben Verborgh Date: Mon, 22 Apr 2019 14:33:23 +0200 Subject: [PATCH] Set termType directly on class. Fixes https://github.com/rdfjs/N3.js/issues/172 --- lib/N3DataFactory.js | 38 ++++++++++++++++++++++++++------------ 1 file changed, 26 insertions(+), 12 deletions(-) diff --git a/lib/N3DataFactory.js b/lib/N3DataFactory.js index bf1a9c90..b9839966 100644 --- a/lib/N3DataFactory.js +++ b/lib/N3DataFactory.js @@ -14,11 +14,6 @@ class Term { this.id = id; } - // ### The term type of this term - get termType() { - return this.constructor.name; - } - // ### The value of this term get value() { return this.id; @@ -46,12 +41,20 @@ class Term { // ## NamedNode constructor -class NamedNode extends Term {} -NamedNode.name = 'NamedNode'; - +class NamedNode extends Term { + // ### The term type of this term + get termType() { + return 'NamedNode'; + } +} // ## Literal constructor class Literal extends Term { + // ### The term type of this term + get termType() { + return 'Literal'; + } + // ### The text value of this literal get value() { return this.id.substring(1, this.id.lastIndexOf('"')); @@ -103,7 +106,6 @@ class Literal extends Term { }; } } -Literal.name = 'Literal'; // ## BlankNode constructor class BlankNode extends Term { @@ -111,24 +113,32 @@ class BlankNode extends Term { super('_:' + name); } + // ### The term type of this term + get termType() { + return 'BlankNode'; + } + // ### The name of this blank node get value() { return this.id.substr(2); } } -BlankNode.name = 'BlankNode'; class Variable extends Term { constructor(name) { super('?' + name); } + // ### The term type of this term + get termType() { + return 'Variable'; + } + // ### The name of this variable get value() { return this.id.substr(1); } } -Variable.name = 'Variable'; // ## DefaultGraph constructor class DefaultGraph extends Term { @@ -137,6 +147,11 @@ class DefaultGraph extends Term { return DEFAULTGRAPH || this; } + // ### The term type of this term + get termType() { + return 'DefaultGraph'; + } + // ### Returns whether this object represents the same term as the other equals(other) { // If both terms were created by this library, @@ -145,7 +160,6 @@ class DefaultGraph extends Term { return (this === other) || (!!other && (this.termType === other.termType)); } } -DefaultGraph.name = 'DefaultGraph'; // ## DefaultGraph singleton DEFAULTGRAPH = new DefaultGraph();