es2015

webpack+react+es2015轻松环境搭建,配置,运行项目

烈酒焚心 提交于 2019-12-04 12:49:26
简介: webpack :是近期最火的一款模块加载器兼打包工具,它能把各种资源,例如JS(含JSX)、coffee、样式(含less/sass)、图片等都作为模块来使用和处理。 react :现在最热门的前端框架,毫无疑问是 React 。 es2015 :ECMAScript 6。 以上是她们的基本定义,想想能将她们结合在一起开发我们的项目是多么的激动人心啊。当然在正式开发之前我们也有很多准备工作需要做好,这也可能是对新手最棘手的问题。下面我们就直接进入正题吧。 环境搭建: 首选我们需下载安装Node.js,下载地址: https://nodejs.org/en/ (注意:为了能支持es2015请下载4.0以上版本) 安装了node之后我们还需要npm也就是包管理器,当然新的node已经集成了npm的。所以此步骤可以跳过了 有了npm后,win+r然后输入cmd打开,然后输入命令: npm install webpack -g 执行命令后我的webpack就全局安装好了,这里提醒一下,在项目文件中我们还需要将webpack写入 package.json(局部安装) 项目创建: 在D盘创建我们的项目文件“reactPro”,目录结构如下: 在cmd中定位项目地址,执行命令: cd D:\reactPro D: 定位完成后,我们利用npm生成package.json文件,执行命令:

Export an imported module

不打扰是莪最后的温柔 提交于 2019-12-04 09:56:01
问题 I have two javascript modules that looks like this: // inner/mod.js export function myFunc() { // ... } // mod.js import * as inner from "./inner/mod"; I would like to export myFunc from mod.js . How can I do this? EDIT: I should clarify that the function is being exported as expected from inner/mod.js but I also want to export the funtion from the outer mod.js . To those asking for clarification, I would like to achieve this: // SomeOtherFile.js import * as mod from "mod"; // NOT inner/mod

webpack配置: 如何同时使用ES2015和JSX

自作多情 提交于 2019-12-03 08:51:03
笔记笔记,网上很多例子都是过期的啊= = 因为jsx转换器整合到babel中了,根本不需要网上所说的jsx-loader sudo npm install webpack webpack-dev-server babel -g sudo npm install react react-dom babel-loader less-loader css-loader style-loader url-loader file-loader babel-preset-es2015 babel-preset-react --save-dev module.exports = { entry: { main: './src/index.jsx', es5:'./src/es6.js' }, output: { path: 'build', filename: '[name].build.js' }, resolve: { extensions: ['','.js', '.jsx'] }, module: { loaders: [{ test: /\.jsx$/, loader: 'babel-loader', query:{ presets:['es2015','react'] } }, { test: /\.js$/, loader: 'babel-loader', query:{

What is the difference between Reflect.ownKeys(obj) and Object.keys(obj)?

吃可爱长大的小学妹 提交于 2019-12-03 05:25:48
问题 Testing them out in a real simple case yields the same output: const obj = {a: 5, b: 5}; console.log(Reflect.ownKeys(obj)); console.log(Object.keys(obj)); // Result ['a', 'b'] ['a', 'b'] When does Reflect.ownKeys(obj) produce output different from Object.keys(obj) ? 回答1: Object.keys() returns an array of strings, which are the object's own enumerable properties. Reflect.ownKeys(obj) returns the equivalent of: Object.getOwnPropertyNames(target). concat(Object.getOwnPropertySymbols(target)) The

What is the difference between Reflect.ownKeys(obj) and Object.keys(obj)?

橙三吉。 提交于 2019-12-02 19:54:14
Testing them out in a real simple case yields the same output: const obj = {a: 5, b: 5}; console.log(Reflect.ownKeys(obj)); console.log(Object.keys(obj)); // Result ['a', 'b'] ['a', 'b'] When does Reflect.ownKeys(obj) produce output different from Object.keys(obj) ? Object.keys() returns an array of strings, which are the object's own enumerable properties. Reflect.ownKeys(obj) returns the equivalent of: Object.getOwnPropertyNames(target). concat(Object.getOwnPropertySymbols(target)) The Object.getOwnPropertyNames() method returns an array of all properties ( enumerable or not ) found directly

Is React.Component the default extension when exporting?

时光毁灭记忆、已成空白 提交于 2019-12-01 10:36:42
I am looking through some React projects, and sometimes see- export default () => { But other times I see- export default class Entry extends React.Component { . Is there any difference between the two, viz. does export automatically extend React.Component ? What is the best practice? The export default () => you see is a React 0.14+ "Functional Component" . It's a new more concise syntax for writing React components. Both it and the other syntax are fine. These components behave just like a React class with only a render method defined. Since no component instance is created for a functional

Is it possible to call a super setter in ES6 inherited classes?

偶尔善良 提交于 2019-11-30 11:09:48
I'm wondering if the following is in compliance with the ES6 spec: class X { constructor(name) { this._name = name; } get name() { return this._name; } set name(name) { this._name = name + "X"; } } class Y extends X { constructor(name) { super(name); } set name(name) { super.name = name; this._name += "Y"; } } The idea is that let y = new Y(""); y.name = "hi" should result in y.name === "hiXY" being true. As far as I can tell, this doesn't work in Chrome with the ES6 flag turned on. It also doesn't work using Babel with the es2015 flag. Is using super.name = ... in an inherited setter not part

Is it possible to call a super setter in ES6 inherited classes?

北城以北 提交于 2019-11-29 16:42:47
问题 I'm wondering if the following is in compliance with the ES6 spec: class X { constructor(name) { this._name = name; } get name() { return this._name; } set name(name) { this._name = name + "X"; } } class Y extends X { constructor(name) { super(name); } set name(name) { super.name = name; this._name += "Y"; } } The idea is that let y = new Y(""); y.name = "hi" should result in y.name === "hiXY" being true. As far as I can tell, this doesn't work in Chrome with the ES6 flag turned on. It also

Why must export/import declarations be on top level in es2015?

╄→尐↘猪︶ㄣ 提交于 2019-11-28 09:43:49
I started using es2015 with babel in last project. When I try to do import or export inside if condition, I have an error 'import' and 'export' may only appear at the top level . I see a lot of cases for that and it works good with require , but not with es2015 modules. Is there any reason for this limitation? JavaScript performs static analysis on ES6 modules. This means you cannot dynamically perform imports or exports. Read section 4.2 of this article for more information : A module's structure being static means that you can determine imports and exports at compile time (statically) – you

Setting an ES6 class getter to enumerable

半世苍凉 提交于 2019-11-28 08:09:40
I have an ES6 class (transcompiled with babeljs) with a getter property. I understand that these properties are not enumerable by default. However, I do not understand why I am not able to make the property enumerable using Object.defineProperty // Declare class class Person { constructor(myName) { this.name = myName; } get greeting() { return `Hello, I'm ${this.name}`; } } // Make enumerable (doesn't work) Object.defineProperty(Person, 'greeting', {enumerable: true}); // Create an instance and get enumerable properties var person = new Person('Billy'); var enumerableProperties = Object.keys