PyClass - Write Python Class in JS
Write Python style class in JS, compatible for Nodejs and Browsers.
No var me/self/_i/SELF/that/_this_/_that_ = this
in your JS any more…
Install
npm install pyclass
bower install pyclass
Features
new Class([Parent,] function(){})
Simple Class definitionself
Self Auto-Binded, avoidthis
__init__
Clear initializer__static__
Simplest way to add static member for Classparent()
Call parent method as you wish.
Usage & Demo
var Class = // Person as a Classvar Person = { // __init__ is initializer this { self_name = name self_age = age } // self is not this, so is not a keyword. this { ; } // add static members for Class this__static__ = { console } } // extend from Personvar Student = Person { this { // call parent init method selfparentname age self_school = school } this { // call parent sayHi selfparent; ; }} var james = 'James' 2;james // ==> Hi, I am James, I am 2 years old. Person // ==> Haha, I am going to sleep now var lily = 'Lily' 12 'Some Nice High School'lily; // ==> Hi, I am Lily, I am 12 years old. // ==> And now, I am a student in Some Nice High SchoolStudent // ==> Haha, I am going to sleep now
License
pyclass
is available under the terms of the MIT License.