Download the full version or the minified version here:
Version 1.4.0 - MIT licensed
Implementing class like functionality using prototypal inheritance.
Making object oriented programming in JavaScript a bit easier, at least for people with a background in class based programming languages like C++, Java and C#.
Supported object oriented features:
MClass tries to stay close to the priciples of prototypal inheritance (in contrast to some other oop libraries)
Because mClass provides private functions and variables, it provides better encapsulation and decoupling than classes from ECMAScript 2015 (6th edition), making mClass useful even in the newest version of JavaScript.
Possible features to add in the future: interfaces and ES5 object methods support.
The ‘m’ in mClass stands for module pattern, which is used to provide private variables and functions.
var Bird = mClass({ // inherit from another class extends: Animal, // Override public method and member public: { sound: function() { return "tweet"; }, legs: 2 } }); var bird = new Bird();
Take a look at the annotated unit tests for more examples.
The easiest way is to use a content delivery network. Just paste the following code in your HTML:
<script src="https://cdn.jsdelivr.net/mclass/1.4.0/mclass-min.js" integrity="sha384-pow1ICcgntcic3w/14Pxoa8jjIkhQpdulrQ1smUTZgrgtD8ppcl9qJqOJQKNnGFz" crossorigin="anonymous"></script>
For a modular approach, mClass supports both AMD and CommonJS.
require(['mclass'], function(mClass) { // your code here... }
var mClass = require("./mclass");
To install the whole package, you can use one of the following commands:
git clone https://github.com/edwinm/mClass.git npm install mclass --save-dev bower install mclass
You can run the unit tests. Let me know when you see a test fail.
MClass is copyright 2015 Edwin Martin and released under the open source MIT license. The code is available on GitHub, where you can clone and improve it and make pull requests.