Skip to main content
Module

x/ohm_js/src/Namespace.js

A library and language for building parsers, interpreters, compilers, etc.
Go to Latest
File
'use strict';
// --------------------------------------------------------------------// Private stuff// --------------------------------------------------------------------
function Namespace() {}Namespace.prototype = Object.create(null);
Namespace.asNamespace = function(objOrNamespace) { if (objOrNamespace instanceof Namespace) { return objOrNamespace; } return Namespace.createNamespace(objOrNamespace);};
// Create a new namespace. If `optProps` is specified, all of its properties// will be copied to the new namespace.Namespace.createNamespace = function(optProps) { return Namespace.extend(Namespace.prototype, optProps);};
// Create a new namespace which extends another namespace. If `optProps` is// specified, all of its properties will be copied to the new namespace.Namespace.extend = function(namespace, optProps) { if (namespace !== Namespace.prototype && !(namespace instanceof Namespace)) { throw new TypeError('not a Namespace object: ' + namespace); } const ns = Object.create(namespace, { constructor: { value: Namespace, enumerable: false, writable: true, configurable: true, }, }); return Object.assign(ns, optProps);};
// TODO: Should this be a regular method?Namespace.toString = function(ns) { return Object.prototype.toString.call(ns);};
// --------------------------------------------------------------------// Exports// --------------------------------------------------------------------
module.exports = Namespace;