Skip to content

Commit

Permalink
readme update
Browse files Browse the repository at this point in the history
  • Loading branch information
radubrehar committed Jul 10, 2014
1 parent b562943 commit cd0287a
Show file tree
Hide file tree
Showing 4 changed files with 148 additions and 98 deletions.
65 changes: 46 additions & 19 deletions README.md
Expand Up @@ -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.

Expand All @@ -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
Expand Down Expand Up @@ -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.
Expand Down

0 comments on commit cd0287a

Please sign in to comment.