diff --git a/README.md b/README.md index 0a17827..41ae8d4 100644 --- a/README.md +++ b/README.md @@ -66,28 +66,12 @@ You can use the class ```alias``` in order to easily reference which class you w var Vehicle = classy.getClass('vehicle') ``` -## Override and callOverriden - -Overriding is simple, just call classy.override -```js -classy.override(Car, { - getName: function(){ - return this.callOverriden() + ', great car' - } -}) -``` -or, if you don't have a reference to the class, but only have the alias -```js -classy.override('car', { - getName: function(){ - return this.callOverriden() + ', great car' - } -}) -``` ## Aliases -When defining a class, you can specify a string property named alias. `classy` keeps a reference to each class based on the specified alias. If no alias is given, one is generated anyway. +When defining a class, you can specify a string property named `alias`. + +`classy` keeps a reference to each class based on the specified alias. If no alias is given, one is generated anyway. Using the alias allows you to reference, extend or override a class by the alias, without the need for an explicit reference to the class. @@ -111,6 +95,25 @@ Notice that when defining the rectangle class, instead of saying we extend the S Whenever an alias is expected, you can use either the alias, or the class itself (in classy.define, classy.override, classy.getClass, etc) +## Override and callOverriden + +Overriding is simple, just call `classy.override` with the class alias or the class reference as the first param, and an object with properties to override as a second param. +```js +classy.override(Car, { + getName: function(){ + return this.callOverriden() + ', great car' + } +}) +``` +or, if you don't have a reference to the class, but only have the alias +```js +classy.override('car', { + getName: function(){ + return this.callOverriden() + ', great car' + } +}) +``` + ## ```init``` as constructor Use the ```init``` method as the constructor @@ -148,6 +151,30 @@ var Cat = classy.define({ var lizzy = new Cat({ name: 'lizzy' }) ``` +You can even extend functions/classes not defined with `classy` + +```js +function Animal(sound){ + this.sound = sound +} + +Animal.prototype.makeSound = function(){ + return 'I sound like this: ' + this.sound +} +``` + +var Dog = classy.define({ + extend: Animal, + alias: 'dog', + init: function(){ + this.callSuperWith('bark') //this calls Animal fn + } +}) + +var dog = new Dog() +dog.makeSound() == 'I sound like this: bark' // is true + + ## ```callSuper``` and ```callOverriden``` Use the ```callSuper``` and ```callOverriden``` methods to call the super and overriden methods. You don't have to worry about forwarding the arguments, since this is handled automagically for you. diff --git a/dist/classy.js b/dist/classy.js index de553c4..03b4401 100644 --- a/dist/classy.js +++ b/dist/classy.js @@ -1,4 +1,4 @@ -(function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);throw new Error("Cannot find module '"+o+"'")}var f=n[o]={exports:{}};t[o][0].call(f.exports,function(e){var n=t[o][1][e];return s(n?n:e)},f,f.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o