logo

/Code Snippet|v2.3.0

Module

Static Methods

defineClass(parent, props)defineClass.jsline 57

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
var defineClass = require('tui-code-snippet/defineClass/defineClass'); // node, commonjs

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

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

Parent.staticMethod();

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

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