1
0
mirror of https://github.com/videojs/video.js.git synced 2024-12-29 02:57:21 +02:00
video.js/docs/api/vjs.CoreObject.md
2013-11-04 16:03:51 -08:00

2.1 KiB

vjs.CoreObject

DEFINED IN: src/js/core-object.js#L52

Core Object/Class for objects that use inheritance + contstructors

To create a class that can be subclassed itself, extend the CoreObject class.

var Animal = CoreObject.extend();
var Horse = Animal.extend();

The constructor can be defined through the init property of an object argument.

var Animal = CoreObject.extend({
  init: function(name, sound){
    this.name = name;
  }
});

Other methods and properties can be added the same way, or directly to the prototype.

var Animal = CoreObject.extend({ init: function(name){ this.name = name; }, getName: function(){ return this.name; }, sound: '...' });

Animal.prototype.makeSound = function(){ alert(this.sound); };

To create an instance of a class, use the create method.

var fluffy = Animal.create('Fluffy'); fluffy.getName(); // -> Fluffy

Methods and properties can be overridden in subclasses.

var Horse = Animal.extend({
  sound: 'Neighhhhh!'
});

var horsey = Horse.create('Horsey');
horsey.getName(); // -> Horsey
horsey.makeSound(); // -> Alert: Neighhhhh!

INDEX


METHODS

create() STATIC

Create a new instace of this Object class

var myAnimal = Animal.create();
RETURNS:
  • vjs.CoreObject An instance of a CoreObject subclass

defined in: src/js/core-object.js#L120


extend( props ) STATIC

Create a new object that inherits from this Object

var Animal = CoreObject.extend();
var Horse = Animal.extend();
PARAMETERS:
  • props Object Functions and properties to be applied to the
RETURNS:
  • vjs.CoreObject An object that inherits from CoreObject

defined in: src/js/core-object.js#L70