Nobody Preheats Microwaves
Share your code. npm Orgs help your team discover, share, and reuse code. Create a free org »

make-symbol

0.1.0 • Public • Published

Make Symbol

A thin wrapper over Symbol() with a very naive fallback. Perfect for "semi-private" properties on classes.

Installation

npm install --save make-symbol

Usage

var makeSymbol = require('make-symbol')
var Name = makeSymbol('name')
 
function Person (name) {
  this[Name] = name
}
 
Object.defineProperty(Person.prototype, 'name', {
  get: function () { return this[Name] },
  enumerable: true
})
var linus = new Person('linus')
 
linus.name // 'linus'
 
linus.name = 'test'
 
linus.name // 'linus'

API

makeSymbol(name: string)

Returns a new Symbol with the provided name.

If Symbol is not available in the current runtime, the name prefixed with '_' will be returned (e.g makeSymbol('linus') will return '_linus').

Keywords

none

install

npm i make-symbol

Downloadsweekly downloads

5

version

0.1.0

license

MIT

homepage

github.com

repository

Gitgithub

last publish

collaborators

  • avatar
Report a vulnerability