Skip to content

Latest commit

 

History

History
93 lines (63 loc) · 2.14 KB

vjs.CoreObject.md

File metadata and controls

93 lines (63 loc) · 2.14 KB

vjs.CoreObject

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

Core Object/Class for objects that use inheritance + constructors

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 instance 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