Giter Club home page Giter Club logo

Comments (11)

sebmck avatar sebmck commented on May 13, 2024 6

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.

zertosh avatar zertosh commented on May 13, 2024 5

@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.

sebmck avatar sebmck commented on May 13, 2024 2

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.

thom4parisot avatar thom4parisot commented on May 13, 2024

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.

thom4parisot avatar thom4parisot commented on May 13, 2024

👍 ah that's great thanks! I did not know it worked for non-class declarations. Thanks :-)

from babelify.

sebmck avatar sebmck commented on May 13, 2024

No problem! Happy to answer any questions, feel free to check out our gitter room too.

from babelify.

IngwiePhoenix avatar IngwiePhoenix commented on May 13, 2024

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.

IngwiePhoenix avatar IngwiePhoenix commented on May 13, 2024

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.

zertosh avatar zertosh commented on May 13, 2024

Presets don't take options.

from babelify.

brendensoares avatar brendensoares commented on May 13, 2024

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.

loganfsmyth avatar loganfsmyth commented on May 13, 2024

@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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.