posrix / Es6 Class Bind All
Licence: mit
Automaticlly bind 'this' scope of all methods in es6 class
Stars: ✭ 10
Programming Languages
javascript
184084 projects - #8 most used programming language
es6
455 projects
Labels
Projects that are alternatives of or similar to Es6 Class Bind All
Php Curl Class
PHP Curl Class makes it easy to send HTTP requests and integrate with web APIs
Stars: ✭ 2,903 (+28930%)
Mutual labels: class
Unifi Api Client
A PHP API client class to interact with Ubiquiti's UniFi Controller API
Stars: ✭ 602 (+5920%)
Mutual labels: class
simplevk
SimpleVK это PHP библиотека для быстрой разработки ботов для VK | vk api php class bot sdk library client framework longpoll callback streaming auth
Stars: ✭ 84 (+740%)
Mutual labels: class
Overview
Overview and map of the organization, for the UCSD course COGS108: Data Science in Practice.
Stars: ✭ 111 (+1010%)
Mutual labels: class
Koa Dec Router
An ES6 decorator + class based router, support inherit, override, priority, auto load controllers, etc.
Stars: ✭ 19 (+90%)
Mutual labels: class
angular-ecmascript
Build an AngularJS app using ES6's class system
Stars: ✭ 28 (+180%)
Mutual labels: class
Coolie
Coolie(苦力) helps you to create models (& their constructors) from a JSON file.
Stars: ✭ 508 (+4980%)
Mutual labels: class
PHP-Light-SQL-Parser
This class can parse SQL to get query type, tables, field values, etc.. It takes an string with a SQL statements and parses it to extract its different components. Currently the class can extract the SQL query method, the names of the tables involved in the query and the field values that are passed as parameters. This parser is pretty light re…
Stars: ✭ 23 (+130%)
Mutual labels: class
Kotlin Result
A multiplatform Result monad for modelling success or failure operations.
Stars: ✭ 369 (+3590%)
Mutual labels: class
PsNetTools
PsNetTools is a cross platform PowerShell module to test network features on Windows, Linux and Mac.
Stars: ✭ 13 (+30%)
Mutual labels: class
babel-plugin-private-underscores
Make _classMembers 'private' using symbols
Stars: ✭ 39 (+290%)
Mutual labels: class
Stampit
OOP is better with stamps: Composable object factories.
Stars: ✭ 3,021 (+30110%)
Mutual labels: class
Problem
As you see, too many .bind()
operations in constructor. Once you have tons of classes
are called in callback or whatever something change it's scope, it will be horribly troublesome.
class Person {
constructor() {
this.name = 'Steve'
this.age = 20
this.gender = 'male'
this.setName = this.setName.bind(this)
this.setAge = this.setAge.bind(this)
this.setGender = this.setGender.bind(this)
}
setName(name) {
this.name = name
}
setAge(age) {
this.age = age
},
setGender(gender) {
this.gender = gender
}
}
Easy Way
Bind all methods in constructor.
import es6ClassBindAll from 'es6-class-bind-all'
class Person {
constructor() {
this.name = 'Jack'
this.age = 20
this.gender = 'male'
es6ClassBindAll(this)
}
setName(name) {
this.name = name
}
setAge(age) {
this.age = age
},
setGender(gender) {
this.gender = gender
}
}
Or you can bind specified methods in constructor depend on your situation.
es6ClassBindAll(this, ['setGender'])
Install
yarn add es6-class-bind-all --dev
or npm
npm install es6-class-bind-all --save-dev
License
The MIT License (MIT). Please see License File for more information.
Note that the project description data, including the texts, logos, images, and/or trademarks,
for each open source project belongs to its rightful owner.
If you wish to add or remove any projects, please contact us at [email protected].