node.js (1952B)
1 /** 2 * @license Apache-2.0 3 * 4 * Copyright (c) 2018 The Stdlib Authors. 5 * 6 * Licensed under the Apache License, Version 2.0 (the "License"); 7 * you may not use this file except in compliance with the License. 8 * You may obtain a copy of the License at 9 * 10 * http://www.apache.org/licenses/LICENSE-2.0 11 * 12 * Unless required by applicable law or agreed to in writing, software 13 * distributed under the License is distributed on an "AS IS" BASIS, 14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 * See the License for the specific language governing permissions and 16 * limitations under the License. 17 */ 18 19 'use strict'; 20 21 // MODULES // 22 23 var defineProperty = require( './../../define-property' ); 24 25 26 // MAIN // 27 28 /** 29 * List node constructor. 30 * 31 * @private 32 * @constructor 33 * @param {*} value - node value 34 * @returns {Node} Node instance 35 * 36 * @example 37 * var node = new Node( 'foo' ); 38 * // returns <Node> 39 */ 40 function Node( value ) { // eslint-disable-line stdlib/no-redeclare 41 // Why getters? Because some of the list APIs will return the list "node", not the value. In which case, the node API is no longer private and we have to guard against users mucking about (deleting, updating, etc) with property values (in particular, the `next` and `prev` properties). 42 defineProperty( this, 'next', { 43 'configurable': false, 44 'enumerable': true, 45 'get': function get() { // eslint-disable-line no-restricted-syntax 46 return this._next; 47 } 48 }); 49 defineProperty( this, 'prev', { 50 'configurable': false, 51 'enumerable': true, 52 'get': function get() { // eslint-disable-line no-restricted-syntax 53 return this._prev; 54 } 55 }); 56 this.value = value; 57 58 defineProperty( this, '_next', { 59 'configurable': false, 60 'enumerable': false, 61 'writable': true, 62 'value': null 63 }); 64 defineProperty( this, '_prev', { 65 'configurable': false, 66 'enumerable': false, 67 'writable': true, 68 'value': null 69 }); 70 71 return this; 72 } 73 74 75 // EXPORTS // 76 77 module.exports = Node;