Embryo.js – The most simple JavaScript inheritance library
Embryo.js is a JavaScript library that I created in order to develop in JavaScript with classes. The world of object-oriented programming is offered to us in order to make beautiful applications 😉 Here’s what you can do with Embryo in a very simple way:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
var Human = Embryo.extend({ '_type': 'Human', properties : { name: 'John', score: 1000, power: 2, options: [ 'super', ] }, init: function() { this.lifes = 3 }, walk: function() { console.log('walk', this.power) } }) var Superman = Human.extend({ '_type': 'Superman', properties : { name: 'Clark Kent', score: 5000, power: 10, options: [ 'super', 'godness', 'unlimited' ] }, init: function() { this.lifes = 10 }, fly: function() { console.log('fly', this.power) } }) var human = new Human() human.walk() // -> walk: 2 console.log( human.getScore() ) // -> 1000 console.log( human.getName() ) // -> John console.log( human.getOptions() ) // -> ['super'] var superman = new Superman() superman.walk() // -> walk: 10 superman.fly() // -> fly: 10 console.log( human instanceof Human ) // -> true console.log( human instanceof Superman ) // -> false console.log( superman instanceof Human ) // -> true |
Github : https://github.com/oOthkOo/embryo.js