YUI Dependency Management
Add a t-rabbits module, then add a t-killer-rabbits module that requires t-rabbit to create a class KillerRabbit class that extends RegularRabbits.
Also refactor output function to use node-base, instead of writing directly with document.write.
// Build adds the boilerplate for you
YUI.add('t-rabbits', function(Y) {
Y.namespace('Rabbits');
/**
* Constructor function to create regular rabbits
* @param name {String} The name of the rabbit
* @constructor
*/
Y.Rabbits.RegularRabbit = function(name) {
this.name = name;
if (name) {
this._writeOutput('Created RegularRabbit: ' + this.name);
}
};
/**
* This method appends a string to the contents of the output div
* @param str {String} The string to append
*/
Y.Rabbits.RegularRabbit.prototype._writeOutput = function(str) {
Y.one('#output').append('<p>' + str + '</p>');
};
/**
* This method lets our rabbits speak
* @param what {String} Whatever the rabbit has to say
*/
Y.Rabbits.RegularRabbit.prototype.speak = function(what) {
this._writeOutput('<blockquote>' + this.name + ' says: ' + what + '</blockquote>');
};
// The build also adds this boilerplate!
}, '3.5.0', {
requires: ['node-base'] // Used to "writeOutput"
});
YUI.add('t-killer-rabbits', function(Y) {
Y.namespace('Rabbits');
/**
* Constructor function to create killer rabbits
* @param name {String} The name of the rabbit
* @param eyes {String} The color of the eyes of the killer rabbit
* @constructor
*/
Y.Rabbits.KillerRabbit = function(name, eyes) {
Y.Rabbits.RegularRabbit.call(this, name);
this.eyes = eyes;
this._writeOutput(this.name + ' is now a ' + this.eyes + '-eyed KillerRabbit!');
}
// The prototype is a RegularRabbit, also fix the constructor reference
Y.Rabbits.KillerRabbit.prototype = new Y.Rabbits.RegularRabbit();
Y.Rabbits.KillerRabbit.prototype.constructor = Y.Rabbits.KillerRabbit;
/**
* Kills a victim
* @param who {String} The name of the victim killed by this rabbit
*/
Y.Rabbits.KillerRabbit.prototype.kill = function(who) {
...
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.