logo

/Code Snippet|v2.3.3

Module

Static Methods

defineClass(parent, props)defineClass.jsline 60

Help a constructor to be defined and to inherit from the other constructors

PARAMETERS
NameTypeDescription

parent

[ * ]

Parent constructor

props

Object

Members of constructor

PROPERTIES
NameTypeDescription

init

Function

Initialization method

static

[ Object ]

Static members of constructor

RETURNS:
{

*

} - Constructor
EXAMPLES
// ES6
import defineClass from 'tui-code-snippet/defineClass/defineClass'; 

// CommonJS
const defineClass = require('tui-code-snippet/defineClass/defineClass'); 

//-- #2. Use property --//
const Parent = defineClass({
  init: function() { // constuructor
    this.name = 'made by def';
  },
  method: function() {
    // ...
  },
  static: {
    staticMethod: function() {
      // ...
    }
  }
});

const Child = defineClass(Parent, {
  childMethod: function() {}
});

Parent.staticMethod();

const parentInstance = new Parent();
console.log(parentInstance.name); //made by def
parentInstance.staticMethod(); // Error

const childInstance = new Child();
childInstance.method();
childInstance.childMethod();
Resizable