Static function.

Base function implementing class declaration in the Yandex.Maps API. Use this function to declare a new class, specify a set of methods for it and inherit from another class.

The "superclass" field is appended to the child class, specifying the prototype of the parent class. Use the 'constructor' field of the 'superclass' object to refer to the constructor of the parent class.

Returns class.

{ Object } util.defineClass(constructor[, parentClass[, override]])


Parameter Default value Description
constructor *

Type: Function

Class constructor.


Type: Function

Parent class to inherit from. This argument may be omitted.


Type: Object

Set of additional fields and functions that will be appended to the class prototype. There can be several sources (the function can have any number of parameters), and data is copied from right to left (the last argument has highest priority during copying).

* Mandatory parameter/option.



// Declaring a class with methods.
var MyClass = ymaps.util.defineClass(function () {
   this.field = 'fieldValue';
    }, {
   doSomethingAwesome: function () {
  return 'methodResult';
   stop: function () {

    object = new MyClass();
    console.log(object.field); // 'fieldValue'
   console.log(object.doSomethingAwesome()); // 'methodResult'


// Creating a custom class for a button, inherited from the base class of the button control.
// Pressing the button will switch the type of map tiles.
var CustomControl = ymaps.util.defineClass(function () {
    // Defining a limited set of options without a possibility to change them from outside.
    var data = {
   data: { content: 'Change the map type' },
   options: {
  selectOnClick: false,
  maxWidth: 150
    CustomControl.superclass.constructor.call(this, data);
}, ymaps.control.Button, {
    // Setting a list of class methods.

    // Overriding the button enable and disable methods.
    enable: function () {
   // You must call base class methods
   // to avoid breaking the button logic.
   // Enabling and disabling button behavior.
   this.events.add('click', this.switchType, this);

    disable: function () {
   this.events.remove('click', this.switchType, this);

    // Implementing our own methods.
    switchType: function () {
   var map = this.getMap();
   if (map) {
  if (map.getType() == 'yandex#map') {
  } else {

    setSchemeMapType: function () {
   var map = this.getMap();
   if (map) {

    setSatelliteMapType: function () {
   var map = this.getMap();
   if (map) {
// Instantiating a new class and adding it to the map.
var typeSwitcherButton = new CustomControl();
// The map creation code was omitted in this example.
// Calling the method of the class instance.