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').

Versions

Current Tags

  • Version
    Downloads (Last 7 Days)
    • Tag
  • 0.1.0
    1
    • latest

Version History

  • Version
    Downloads (Last 7 Days)
    • Published
  • 0.1.0
    1

Package Sidebar

Install

npm i make-symbol

Weekly Downloads

1

Version

0.1.0

License

MIT

Last publish

Collaborators

  • linusu