Extending SpringRoll

Matt Karl edited this page Nov 11, 2015 · 3 revisions

Since JavaScript is not an object-oriented language, there are different styles of doing pseudo-class inheritance. Here's the SpringRoll recommended way using a basic example of extending springroll.Application.

(function(){

	// Include the Application class to use as a local reference
	var Application = include('springroll.Application');
	
	// Define our new class which will extend Application
	var SubApp = function(options)
	{
		// This calls the Application's constructor
		Application.call(this, options);
	};

	// The parent class's prototype reference
	// we can use this later to override methods
	// see destroy() below
	var s = Application.prototype;

	// Inherit the prototype chain from Application
	var p = Application.extend(SubApp);

	// Example of overriding and calling the parent class
	p.destroy = function()
	{
		// Call Application's destroy() method
		s.destroy.call(this);
	};

	// Assign to a global namespace
	namespace('myproject').SubApp = SubApp;

}());
You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.
Press h to open a hovercard with more details.