
Security News
Deno 2.2 Improves Dependency Management and Expands Node.js Compatibility
Deno 2.2 enhances Node.js compatibility, improves dependency management, adds OpenTelemetry support, and expands linting and task automation for developers.
babel-plugin-promote-class-properties
Advanced tools
Babel plugin to replace old code using ClassProperties feature
Babel plugin to replace old code taking advantage of ClassProperties feature
class Foo {
constructor() {
this.foo = this.foo.bind(this);
this.bar = this.bar.bind(this);
}
foo(arg1, arg2) {
console.log(arg1, arg2)
}
bar(lol) {
return lol;
}
}
class Foo {
foo = (arg1, arg2) => {
console.log(arg1, arg2)
}
bar = (lol) => {
return lol;
}
}
Declaring event listeners is a common thing to do on the daily bases of every JS developer. In real life applications we see a lot of this:
class App extends React.Component {
constructor() {
this.onLoad = this.onLoad.bind(this);
this.state = {width: 0, height: 0};
}
onLoad({target: {height, width}}) {
this.setState({width, height});
}
render() {
const {width, height} = this.state;
return (
<div>
<div>{width}x{height}</div>
<img onLoad={this.onLoad} />
</div>
);
}
}
We need to do
this.onLoad = this.onLoad.bind(this);
Because of the way of this context is handled on addEventListener
, see The_value_of_this_within_the_handler, from MDN:
If attaching a handler function to an element using addEventListener(), the value of this inside the handler is a reference to the element. It is the same as the value of the currentTarget property of the event argument that is passed to the handler.
Doing that reassignment, we keep the react component instance as this value and we can do operations like setState
while still having access to the DOM element.
<img onError={this.onImgError.bind(this) />
document.body.addEventListener('scroll', this.onScroll.bind(this));
FAQs
Babel plugin to replace old code using ClassProperties feature
The npm package babel-plugin-promote-class-properties receives a total of 2 weekly downloads. As such, babel-plugin-promote-class-properties popularity was classified as not popular.
We found that babel-plugin-promote-class-properties demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Deno 2.2 enhances Node.js compatibility, improves dependency management, adds OpenTelemetry support, and expands linting and task automation for developers.
Security News
React's CRA deprecation announcement sparked community criticism over framework recommendations, leading to quick updates acknowledging build tools like Vite as valid alternatives.
Security News
Ransomware payment rates hit an all-time low in 2024 as law enforcement crackdowns, stronger defenses, and shifting policies make attacks riskier and less profitable.