prototype-and-class
Простое прототипирование и наследование
Easy prototyping and inheritance
Install
$ npm i protorype-and-class --save
//html
<script type="text/javascript" src="class.js"></script>
//require.js
require.config({
paths: {
class: 'lib/class'
}
shim: {
"class": {
exports: "Class"
}
}
});
//Common.js
var Class = require('prototype-and-class');
Example
var Class = require('prototype-and-class');
var Animal = Class.extend({
say: function(){
console.log('Animal: say');
}
});
var animal = new Animal();
animal.say();
var Cat = Animal.extend({
sayMeow: function(){
console.log('cat: meow');
}
});
var cat = new Cat();
cat.say();
cat.sayMeow();
var bigCat = cat.extend({
sayMeow: function(){
console.log('bigCat: MEOW')
},
weight: 10.5
});
bigCat.sayMeow();
console.log('weight:', bigCat.weight);
Init
var Base = Class.extend({
init: function(){
console.log('Method init');
}
);
var base = new Class();//write to the console 'Method init'