stampit API
  • Introduction
  • Essentials
    • What is a Stamp
    • Installation
    • Specification
      • Merging algorithm
      • Object creation internals
    • FAQ
  • API
    • Quick start
    • Basics
    • Methods
    • Properties
    • Deep properties
    • Initializers
    • Static properties
    • Static deep properties
    • Configuration
    • Deep configuration
    • Composers
    • Property descriptors
    • Static property descriptors
    • Name
  • Ecosystem
    • Ecosystem Overview
    • @stamp/collision
    • @stamp/required
    • @stamp/privatize
    • @stamp/named (DEPRECATED)
    • @stamp/instanceof
Powered by GitBook
On this page
  1. API

Static property descriptors

PreviousProperty descriptorsNextName

Last updated 6 years ago

Static property descriptors are . They are applied last thing when a stamp is being composed.

let MyStamp = stampit() // empty stamp creates empty objects

MyStamp.name === 'Stamp' // every stamp default name is "Stamp"

MyStamp = MyStamp.staticPropertyDescriptors({
  name: { value: 'MyStamp' } // this meta data will be applied just after composition, i.e. immediately
})

MyStamp.name === 'MyStamp'

The code above adds some more metadata to the MyStamp stamp. It overwrites function name. (Property descriptors is the only way to change a function name.)

NOTE

The stampit and @stamp/it modules have the built in.

const MyStamp = stampit({ name: 'MyStamp' })
MyStamp.name === 'MyStamp'

Other ways to add static property descriptors

Exactly the same stamp can be created in few ways. Here they all are.

const myStampName = {
  name: { value: 'MyStamp }
}

const NamedStamp = stampit({
  staticPropertyDescriptors: myStampName
})

const NamedStamp = stampit.staticPropertyDescriptors(myStampName)

const NamedStamp = stampit().staticPropertyDescriptors(myStampName)
standard JavaScript property descriptors
"name" feature