Comments (11)
You can also use the method shorthand syntax inside object literals like so:
let React = require('react');
module.exports = React.createClass({
getInitialState() { return username: 'John Doe'; },
render() {
return (<div>{this.state.username}</div>);
}
});
from babelify.
@IngwiePhoenix That's being done by babel-plugin-transform-es2015-modules-commonjs. It's part of babel-preset-es2015. You can turn off transforming the top level this
to undefined
by passing it {allowTopLevelThis: true}
. Like this:
plugins: [
[require('babel-plugin-transform-es2015-modules-commonjs'), {allowTopLevelThis: true}]
]
That of course means that you can't use a preset, you'll have to specify the transforms individually so you can pass in that option.
from babelify.
See babel/babel#733. Arrow functions aren't equivalent to normal functions, whenever you use this
inside them it refers to the outer this
.
from babelify.
OK I see thanks! I suppose this would have worked if I used the Component extends React.Component
and the new method definition (aka render(){ ... }
. Thanks :-)
from babelify.
👍 ah that's great thanks! I did not know it worked for non-class declarations. Thanks :-)
from babelify.
No problem! Happy to answer any questions, feel free to check out our gitter room too.
from babelify.
Sorry for butting in all of a sudden :)
I just began using Babel alltogether and realized, that sometimes this:
(function(){
// ...
}).call(this);
Would become this:
(function(){
// ...
}).call(undefined);
instead. Namely, the undefined-treatment happens against this line: https://github.com/musictheory/oj/blob/master/src/runtime.js#L375
What is the best way to get rid of that behaviour, altogether?
from babelify.
Really? How come this won't work with a preset?
2015-11-27 5:30 GMT+01:00 Andres Suarez [email protected]:
@IngwiePhoenix https://github.com/IngwiePhoenix That's being done by
babel-plugin-transform-es2015-modules-commonjs. It's part of
babel-preset-es2015 http://babeljs.io/docs/plugins/preset-es2015/. You
can turn off transforming the top level this to undefined by passing it {allowTopLevelThis:
true}
https://github.com/babel/babel/blob/v6.2.2/packages/babel-plugin-transform-es2015-modules-commonjs/src/index.js#L127.
Like this:plugins: [
[require('babel-plugin-transform-es2015-modules-commonjs'), {allowTopLevelThis: true}]
]That of course means that you can't use a preset, you'll have to specify
the transforms individually so you can pass in that option.—
Reply to this email directly or view it on GitHub
#37 (comment).
from babelify.
Presets don't take options.
from babelify.
So the workaround to get this
scoped to the parent scope is the old var that = this
? That's a shame. Also a shame you can't pass in options with the Babel preset :(
from babelify.
@brendensoares It's not clear what you're asking. I'd recommend dropping by our documented support channels or #javascript
on Freenode if you have specific ES6 questions.
from babelify.
Related Issues (20)
- Babel 7 Stable Released HOT 8
- Bundling hyperhtml-element with browserify/babelify not working
- transform-arrow-functions being ignored for external packages? HOT 5
- TypeError: extensions.indexOf is not a function
- TypeError: Cannot read property 'canCompile' of undefined HOT 5
- How to get babelify && preset-env to convert 'const' HOT 3
- Boolean options fail (e.g. --compact true) HOT 1
- usage of babel/polyfills HOT 4
- Not working "Why aren't files in node_modules being transformed?" HOT 14
- Use a Bundler for Development? HOT 1
- tsify + babelify + browserify with threejs modules: SyntaxError: 'import' and 'export' may appear only with 'sourceType: module' (9:0) HOT 17
- Is it possible to disable asyncToGenerator? HOT 2
- TypeError: Cannot read property 'arrayify' of undefined HOT 2
- Is this incompatible with Babel 7? HOT 3
- If I don't specify any Babel plugins or presets, what exactly should happen? HOT 6
- Continued problems with issue #103 ('import' and 'export' may appear only with 'sourceType: module') HOT 4
- How to use with globally installed browserify? HOT 1
- No source being transformed HOT 1
- babelify + gulp with threejs modules: SyntaxError: 'import' and 'export' may appear only with 'sourceType: module' (9:0)
- 'import' and 'export' may appear only with 'sourceType: module' (14:0)
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from babelify.