Skip to content
| Marketplace
Sign in
Visual Studio Code>Snippets>JavaScript Class TemplateNew to Visual Studio Code? Get it now.
JavaScript Class Template

JavaScript Class Template

8rin5x

|
1,809 installs
| (0) | Free
Class template for making a private declaration in JavaScript
Installation
Launch VS Code Quick Open (Ctrl+P), paste the following command, and press enter.
Copied to clipboard
More Info

JavaScript class template

About

Class template for making a private declaration in JavaScript

Usage

Create a class template by entering class:

const ClassName = (function () {
  // Private modifier
  const _ = new Proxy({}, {
    get: (obj, name) => {
      if (obj[name] === undefined) {
        obj[name] = Symbol(name)
      }
      return obj[name]
    },
    set: () => { }
  })

  // constructor
  function ClassName() {
    
  }

  return ClassName
})()

Template usage example

const Example = (function () {
  // Private modifier
  const _ = new Proxy({}, {
    get: (obj, name) => {
      if (obj[name] === undefined) {
        obj[name] = Symbol(name)
      }
      return obj[name]
    },
    set: () => { }
  })

  // constructor
  function Example(privateValue, publicValue) {
    // private instance
    this[_.privateInstanceName] = privateValue
    // public instance
    this.publicInstanceName = publicValue
  }

  // alias
  const proto = Example.prototype

  // private prototype
  proto[_.privatePrototypeName] = function () {}
  // public prototype
  proto.publicPrototypeName = function () {}

  return Example
})()
  • Contact us
  • Jobs
  • Privacy
  • Manage cookies
  • Terms of use
  • Trademarks
© 2025 Microsoft