Last active
August 29, 2015 14:02
-
-
Save ewjoachim/3cb2900d9fd3ce998580 to your computer and use it in GitHub Desktop.
Base class for Javascript
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
define(["jq"], function($){ | |
"use strict"; | |
var Class = function(){}; | |
var minimal_class_definition = | |
{ | |
init: function() | |
{ | |
} | |
}; | |
var extend = function (base_class, additionnal_definition) | |
{ | |
var _class_definition = $.extend({}, base_class._class_definition, additionnal_definition); | |
var new_class = function(){ | |
$.extend(this, _class_definition); | |
this.init.apply(this, arguments); | |
}; | |
new_class._class_definition = _class_definition; | |
return new_class; | |
}; | |
Class = extend(Class, minimal_class_definition); | |
Class.extend = extend; | |
return Class; | |
} | |
); | |
// a class wouls look like that : | |
/*global define */ | |
define(["Class", "jquery"], | |
function(Class, $){ | |
"use strict"; | |
var ClassName = Class.extend(Class, | |
{ | |
init: function() | |
{ | |
}, | |
} | |
); | |
return ClassName; | |
} | |
); |
unscriptable
commented
Jun 16, 2014
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment