babel

ES6的Public属性和Private属性

时光毁灭记忆、已成空白 提交于 2020-01-07 05:05:42
【推荐】2019 Java 开发者跳槽指南.pdf(吐血整理) >>> 这是一个简单的 Player 类,它包含了我们讨论的有关 ES6 类的所有内容。 JavaScript 代码: class Player { constructor() { this.points = 0 this.assists = 0 this.rebounds = 0 this.steals = 0 } addPoints(amount) { this.points += amount } addAssist() { this.assists++ } addRebound() { this.rebounds++ } addSteal() { this.steals++ } } 我们看看这段代码,我们能不能让它更直观一点呢?方法很好理解,都很自然。那么构造函数呢?什么是 constructor ?为什么我们必须在这里定义实例值?现在,这些问题已经有了答案,但是为什么我们不能向实例中添加 state(状态) ,就像方法那样?比如: JavaScript 代码: class Player { points = 0 assists = 0 rebounds = 0 steals = 0 addPoints(amount) { this.points += amount } addAssist() { this

你好,babel

流过昼夜 提交于 2020-01-07 00:49:00
写在前面 其实学babel是本人2019年Q3的一个计划,因为当时自己做的一个项目需要自己去配babel,也遇到了一些困难,发现自己对babel的了解还是很少的,所以决定好好看下babel;可是后来解决了当时的问题后,由于业务需求很多再加上自己懒了(这才是最终的原因),学习babel的事也就不了了之了。。。拖到了现在0.0 已经进入2020年了,还没有来得及总结自己的19年,但是2020年我要立下一个早该做到的flag,今年的Q1本人要彻底搞懂babel,也不说彻底搞懂啦,最起码本人要做到团队所有的babel问题我都可以直接解决。 其实我也不是为了搞懂babel而想着去学,我最近也看了一些关于babel的博客,慢慢的发现babel其实很有意思,去研究一个东西对自己的技术成长也会有提升,话不多说学就完了,奥利给! 对babel的基本理解 其实在学babel之前我也做了一些功课,对babel也有一些基本的理解,我先基本的谈谈我对最基本的理解 babel是什么? babel就是一个转换器,它可以把高阶ES2015+版本的代码转换成浏览器可以解析的代码(向后兼容)。 为什么要用babel? 本人是做前端的,主要就是在用js,js版本也是一年比一年在更新,每次更新都会出一些更方便好用的方法,到现在ECMAScript已经到了ES10了,已经迭代了10个版本

Vue.js

狂风中的少年 提交于 2020-01-06 18:20:05
【推荐】2019 Java 开发者跳槽指南.pdf(吐血整理) >>> 官方教程Prop 中的例子使用的是全局注册的组件。但是我使用了babel,组件是局部注册的: components: { IconBase, IconBird, Products, Billing, Account, }, 官方教程容易使人误解为需要在父组件中使用props选项。 菜鸟教程 中也有不严谨的描述: prop 是父组件用来传递数据的一个自定义属性。 我认为应该改为: prop 是子组件用来接受父组件传递过来的数据的一个自定义属性。 正确的理解是,子组件需要使用props选项声明自己的prop属性。然后在父组件调用子组件时进行绑定。 示例如下 子组件需要显式声明“prop”: <script> export default { name: 'Account', props: ['userName'], data() { return { current: ['1'], }; }, }; </script> 父组件中,子组件使用v-bind动态绑定自己的props到父组件的数据中: <template> <a-layout-content class="lay-c"> <Products v-if="navKey === 'Products'" /> <Billing v-if="navKey ===

webpack快速使用笔记

女生的网名这么多〃 提交于 2020-01-06 18:19:28
【推荐】2019 Java 开发者跳槽指南.pdf(吐血整理) >>> 一、NPM 1.NPM是随同NodeJS一起安装的包管理工具。 2.安装 npm install npm -g npm -v 测试是否成功安装 3.使用淘宝镜像(cnpm命令) npm install -g cnpm --registry=https://registry.npm.taobao.org 4.安装模块 npm install <Module Name> 安装好之后,模块包就放在了工程目录下的node_modules目录中,因此在代码中只需要通过 require('express')的方式就可引入,无需指定第三方包路径。 var express = require('Module Name'); 5.全局安装与本地安装 npm install express # 本地安装 npm install express -g # 全局安装 本地安装将安装包放在./node_modules下(运行npm命令时所在的目录), 可以通过require()来引入本地安装的包。 全局安装将安装包放在/usr/local下或者你node的安装目录, 可以直接在命令行里使用。 6.Package.json主要属性说明 name-包名。 version-包的版本号。 description-包的描述。 homepage

babel-node is not getting installed on Heroku

こ雲淡風輕ζ 提交于 2020-01-06 05:35:32
问题 I'm using babel-node for ES6 syntax on Heroku, but I get a build error when I deploy. It says "babel-node: not found". I've tried a clean install on my local computer and it works perfectly. Package.json: { "name": "secret", "version": "0.0.0", "private": true, "scripts": { "start": "./node_modules/.bin/babel-node ./bin/www" }, "engines": { "node": "7.5.0", "npm": "5.0.3" }, "dependencies": { "babel-cli": "^6.24.1", "babel-preset-es2015": "^6.24.1", "babel-preset-stage-0": "^6.24.1", ... } }

react 基础篇 #2 create-react-app

浪子不回头ぞ 提交于 2020-01-06 00:27:43
1. 介绍 在开发react应用时,应该没有人用传统的方法引入react的源文件(js),然后在html编辑吧。 大家都是用webpack + es6来结合react开发前端应用。 这个时候,我们可以手动使用npm来安装各种插件,来从头到尾自己搭建环境。 比如: npm install react react-dom --save npm install babel babel-loader babel-core babel-preset-es2015 babel-preset-react --save npm install babel webpack webpack-dev-server -g 复制代码 虽然自己搭建的过程也是一个很好的学习过程,但是有时候难免遇到各种问题,特别是初学者,而且每次开发一个新应用,都要自己从头搭建,未免太繁琐。 于是,有人根据自己的经验和最佳实践,开发了脚手架,避免开发过程中的重复造轮子和做无用功,从而节省开发时间。 类似这样的脚手架,我扫了网络上比较多人用和关注的,一共发现了三个,它们分别是: react-boilerplate react-redux-starter-kit create-react-app 它们的关注量都非常大,截至写这篇文章为止,在github上的star量是这样的: 由此可见,使用这三个脚手架的人都相当多,最突出的是

Firebase webpack+babel functions not deploying

喜夏-厌秋 提交于 2020-01-05 06:46:52
问题 Is it possible to make firebase functions work with webpack and babel? We need to reuse existing ES6 classes on server side which we can't edit so we need to transpile them to make it work in node. Spent two days on the related tutorials but I'm hitting the problem where firebase can't seem to see functions declared in index.js after they were wrapped by webpack in a function. here is a part of the resulting index.js: (function(module, exports, __webpack_require__) { var functions = __webpack

Flask + Flask-Security + Babel not working

浪子不回头ぞ 提交于 2020-01-05 05:29:47
问题 I have setup with Flask + Babel + Flask Security. Created all translation like this: root main.py translations ru LC_MESSAGES messages.mo messages.po In main.py there is part to setup language which executes: @babel.localeselector def get_locale(): user = getattr(g, 'user', None) if user is not None: print("User locale {}".format(user.locale)) return user.locale # I put here constant to test return 'ru' But http://localhost/login stayed untranslated. Can you please advice where else to dig?

ReactJS: unexpected token '<'

帅比萌擦擦* 提交于 2020-01-04 14:33:10
问题 Hello I tried to search in other questions but none of mentioned solutions I tried did not work for me. When using command: npm start I have an error: ERROR in ./src/index.js Module build failed (from ./node_modules/babel-loader/lib/index.js): SyntaxError: D:/Kodilla/Projekty/webpack-to-do-app/src/index.js: Unexpected > token (6:4) 5 | ReactDOM.render( 6 | <App />, | ^ 7 | document.getElementById('app') 8 | ); Defined command in package.json: "scripts": { "test": "echo \"Error: no test

how to set up grunt + browserify + tsify + babelify?

我与影子孤独终老i 提交于 2020-01-04 06:09:27
问题 I am struggling to set up grunt + browserify + tsify + babelify (with debug). The below gruntfile setting does compile typescript, but no babel transpling is happening. Can anybody let me know how to do this? (i might need to use gulp to do this??) browserify: { main: { src: 'app/scripts/main.ts', dest: 'app/scripts/bundle.js', }, options: { browserifyOptions: { plugin: [['tsify']], transform: [['babelify', {presets: ['es2015'], extensions: ['.ts']}]], debug: true } } } tsconfig.json has