<script src="http://wzrd.in/bundle/csextends"></script>
<h1><a href="https://github.com/bevry/csextends">Coffee-Script Extends</a></h1>
Use the Coffee-Script extends keyword outside of Coffee-Script. Useful for easily extending existing existing classes, e.g. <code>require('csextends')(klass, extensions)</code>, and for providing your module consumers with an easy way to extend your classes, i.e. <code>Backbone.Model.extend(extensions)</code>.
<p>Click "Run" in the blue bar above, and open your console for a demo.</p>
JavaScript
// Create a Class
var Person = function(name){
if ( name ) this.name = name
}
Person.prototype.name = 'Unknown'
Person.prototype.hello = function(){
console.log('Hello '+this.name+'!')
}
// Extend the class
var Child = require('csextends')(Person, {
constructor: function(name, mother, father){
Person.call(this, name)
this.mother = mother
this.father = father
},
mother: null,
father: null,
heyYaAll: function(){
this.hello()
this.mother.hello()
this.father.hello()
}
})
// Create some people
var eve = new Person('Eve')
var adam = new Person('Adam')
var me = new Child(null, eve, adam)
me.heyYaAll()
// Hello Unknown!
// Hello Eve!
// Hello Adam!
// Is me still a person
console.log(me instanceof Person) // true
// Now let's make this easier for people in the future
Person.subclass = require('csextends')
// Now, instead of doing:
// var Child = require('csextends')(Person, extensions)
// We can now do:
// var Child = Person.subclass(extensions)
// Which is very useful for module consumers.
// If you use CoffeeScript, you can accomplish the above by doing:
// class Person
// @subclass: require('csextends')
// Then your javascript consumers can do:
// var Child = Person.subclass(extensions)
// Just as before, which is really good for JavaScript users.
Please Whitelist JSFiddle in your content blocker.
Help keep JSFiddle free for always by one of two ways:
Whitelist JSFiddle in your content blocker (two clicks)
Go PRO and get access to additional PRO features →
Join the 4+ million users, and keep the JSFiddle dream alive.
Ad-free
All ads in the editor and listing pages are turned completely off.
Use pre-released features
You get to try and use features (like the Palette Color Generator) months before everyone else.
Fiddle collections
Sort and categorize your Fiddles into multiple collections.
Private collections and fiddles
You can make as many Private Fiddles, and Private Collections as you wish!
Console
Debug your Fiddle with a minimal built-in JavaScript console.