热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

php和jq开发怎么使用es6,PHP与jquery

本文目录一览:1、phpstorm怎么使用es6语法

本文目录一览:


  • 1、phpstorm怎么使用es6语法


  • 2、请教如何在phpStorm中配置eslint


  • 3、jquery支持es6吗

phpstorm怎么使用es6语法

设置中 语言和框架 Languages Frameworks -》 选中Javascript 然后把 Javascript language version 修改为ECMAScript 6

请教如何在phpStorm中配置eslint

使用ESlint

一、ESLint跟JSLint和JSHint类似,但有以下区别:

1.使用Espree进行js解析(parse)

2.用AST抽象语法树去识别(evaluate)代码中的模式3.每个规则都是独立的插件

二、安装

全局安装:

npm install -g eslint

三、使用

如果是第一次使用,eslint --init 命令帮你完成初始化,生成.eslintrc文件然后eslint test.js test2.js

四、配置

{

"rules": {

"semi": ["error", "always"],

"quotes": ["error", "double"]

}

}

提示有三个level:

"off" or 0 - 关闭这个规则校验

"warn" or 1 - 开启这个规则校验,但只是提醒,不会退出"error" or 2 - 开启这个规则校验,并退出

五、常见问题

1.为什么不用jslint

创建eslint是因为急需插件化的校验工具

2.ESLint跟JSHint、JSCS的比较

ESLint比JSlint要慢2~3倍,因为ESLint在识别代码前需要用Espress构建AST,而JSHint在解析的时候就会识别代码。虽然慢些,但不至于成为痛点。

ESLint比JSCS快,(as ESLint uses a single-pass traversal for analysis whereas JSCS using a querying model.)3.ESLint仅仅是校验还是也检查代码风格

都有。ESLint does both traditional linting (looking for problematic patterns) and style checking (enforcement of conventions). You can use it for both.

4.支持es6吗?

支持。参考配置eslint.org/docs/user-guide/configuring5.支持JSX?

支持,但并不表示支持React。(Yes, ESLint natively supports parsing JSX syntax (this must be enabled in configuration.). Please note that supporting JSX syntax is not the same as supporting React. React applies specific semantics to JSX syntax that ESLint doesn't recognize. We recommend using eslint-plugin-react if you are using React and want React semantics.)5.支持es7吗?

本身不支持,可以使用babel-eslint

六、下面详细介绍下配置,地址eslint.org/docs/user-guide/configuring1.配置ESLint

主要有两种方法配置

(1)配置注释,直接嵌入到js文件中

(2)配置文件,使用js、json或者yaml文件来为整个目录及其子目录配置。形式有:.eslintrc.*文件,或者在package.json中配置eslintConfig字段,或者在命令行里配置。

配置分几个方面:

(1)环境(env):设置你的脚本的目标运行环境,如browser,amd,es6,commonjs等,每种环境有预设的全局变量(2)全局变量:增加的全局变量供运行时使用(3)规则(rules):设定的规则及该规则对应的报错level2.配置解析器选项(Specifying Parser Options)默认仅支持ES5语法,可以设置为es6 es7 jsx等。

{

"parserOptions": {

"ecmaVersion": 6,  // 可选 3 5(默认) 6 7"sourceType": "module", // 可选script(默认) module"ecmaFeatures": {

"jsx": true

},

},

"rules": {

"semi": 2

}

}

3.配置解析器(Specifying Parser),需要本地npm模块{

"parser": "esprima", // Espree(默认) Esprima Babel-ESLint"rules": { "semi": "error" } }

4.配置环境(Specifying Environments),可以多选

browser - browser global variables.

node - Node.js global variables and Node.js scoping.

commonjs - CommonJS global variables and CommonJS scoping (use this for browser-only code that uses Browserify/WebPack).

shared-node-browser - Globals common to both Node and Browser.

es6 - enable all ECMAScript 6 features except for modules.

worker - web workers global variables.

amd - defines require() and define() as global variables as per the amd spec.

mocha - adds all of the Mocha testing global variables.

jasmine - adds all of the Jasmine testing global variables for version 1.3 and 2.0.

jest - Jest global variables.

phantomjs - PhantomJS global variables.

protractor - Protractor global variables.

qunit - QUnit global variables.

jquery - jQuery global variables.

prototypejs - Prototype.js global variables.

shelljs - ShellJS global variables.

meteor - Meteor global variables.

mongo - MongoDB global variables.

applescript - AppleScript global variables.

nashorn - Java 8 Nashorn global variables.

serviceworker - Service Worker global variables.

atomtest - Atom test helper globals.

embertest - Ember test helper globals.

webextensions - WebExtensions globals.

greasemonkey - GreaseMonkey globals.

如果要在待校验文件里面配置可以这样配置:

/*eslint-env node, mocha */

如果要在配置文件中配置:

{

"env": {

"browser": true,

"node": true

}

}

如果在package.json中配置:

{

"name": "mypackage",

"version": "0.0.1",

"eslintConfig": {

"env": {

"browser": true,

"node": true

}

}

}

如果在YAML中配置:

---

env:

browser: true

node: true

也可以用插件

{

"plugins": ["example"],

"env": {

"example/custom": true

}

}

5.配置全局变量(Specifying Globals)

定义了全局变量以后,使用他们,ESLint不会发出警告。

在js文件中定义:

/*global var1, var2*/

设置read only

/*global var1:false, var2:false*/

在配置文件中:

{

"globals": {

"var1": true,

"var2": false

}

}

6.配置插件(Configuring Plugins)

使用npm安装第三方插件

{

"plugins": [

"plugin1",

"eslint-plugin-plugin2"

]

}

7.配置规则(Configuring Rules)

js中配置:

/*eslint eqeqeq: "off", curly: "error"*/

或者:

/*eslint eqeqeq: 0, curly: 2*/

如果规则有多个选项:

/*eslint quotes: ["error", "double"], curly: 2*/在配置文件中设置:

{

"rules": {

"eqeqeq": "off",

"curly": "error",

"quotes": ["error", "double"]

}

}

使用插件:

{

"plugins": [

"plugin1"

],

"rules": {

"eqeqeq": "off",

"curly": "error",

"quotes": ["error", "double"],

"plugin1/rule1": "error"

}

}

/*eslint "plugin1/rule1": "error" */

临时关闭eslint校验:

/*eslint-disable */

//Disable all rules between comments

alert('foo');

/*eslint-enable */

/*eslint-disable no-alert, no-console */

alert('foo');

console.log('bar');

/*eslint-enable no-alert */

在js特定行关闭校验:

alert('foo'); // eslint-disable-line

// eslint-disable-next-line

alert('foo');

alert('foo'); // eslint-disable-line no-alert, quotes, semi// eslint-disable-next-line no-alert, quotes, semialert('foo');

8.增加共享设置(Adding Shared Settings)

{

"settings": {

"sharedData": "Hello"

}

}

9.使用配置文件

eslint -c myconfig.json myfiletotest.js

10.继承配置文件(Extending Configuration Files)

{

"extends": [

"./node_modules/coding-standard/eslintDefaults.js",// Override eslintDefaults.js

"./node_modules/coding-standard/.eslintrc-es6",// Override .eslintrc-es6

"./node_modules/coding-standard/.eslintrc-jsx",],

"rules": {

// Override any settings from the "parent" configuration"eqeqeq": "warn"

}

}

11.忽略文件或目录(Ignoring Files and Directories)建立.eslintignore文件

# /node_modules and /bower_components ignored by default# Ignore files compiled from TypeScript and CoffeeScript**/*.{ts,coffee}.js

# Ignore built files except build/index.jsbuild/

!build/index.js

jquery支持es6吗

是否支持es6主要看浏览器。

jquery是把常用的js方法进行了封装,并兼容各浏览器,但对es6并没有进行浏览器兼容。在支持es6的新版本浏览器下,jquery也可以直接使用es6语法。

如果需要对低版本浏览器兼容运行es6的话一般使用babel。


推荐阅读
  • 深入解析Android中图像资源的内存占用问题及其优化策略
    在Android开发过程中,图像资源的内存占用是一个值得关注的问题。本文将探讨图像内存占用与哪些因素相关,包括设备性能的影响,并提供一系列优化策略,帮助开发者有效管理图像资源,提升应用性能。 ... [详细]
  • 探讨在特定情况下使用 Knockout.js 的 if 或 visible 绑定的最佳实践,特别是在处理未定义对象时的策略。 ... [详细]
  • 深入解析JVM垃圾收集器
    本文基于《深入理解Java虚拟机:JVM高级特性与最佳实践》第二版,详细探讨了JVM中不同类型的垃圾收集器及其工作原理。通过介绍各种垃圾收集器的特性和应用场景,帮助读者更好地理解和优化JVM内存管理。 ... [详细]
  • 本文将介绍如何编写一些有趣的VBScript脚本,这些脚本可以在朋友之间进行无害的恶作剧。通过简单的代码示例,帮助您了解VBScript的基本语法和功能。 ... [详细]
  • 本文介绍了如何使用 Spring Boot DevTools 实现应用程序在开发过程中自动重启。这一特性显著提高了开发效率,特别是在集成开发环境(IDE)中工作时,能够提供快速的反馈循环。默认情况下,DevTools 会监控类路径上的文件变化,并根据需要触发应用重启。 ... [详细]
  • 本文详细介绍了 Dockerfile 的编写方法及其在网络配置中的应用,涵盖基础指令、镜像构建与发布流程,并深入探讨了 Docker 的默认网络、容器互联及自定义网络的实现。 ... [详细]
  • 本文深入探讨了 Java 中的 Serializable 接口,解释了其实现机制、用途及注意事项,帮助开发者更好地理解和使用序列化功能。 ... [详细]
  • 在网站制作中随时可用的10个 HTML5 代码片段
    HTML很容易写,但创建网页时,您经常需要重复做同样的任务,如创建表单。在这篇文章中,我收集了10个超有用的HTML代码片段,有HTML5启动模板、空白图片、打电话和发短信、自动完 ... [详细]
  • Spring Boot 中静态资源映射详解
    本文深入探讨了 Spring Boot 如何简化 Web 应用中的静态资源管理,包括默认的静态资源映射规则、WebJars 的使用以及静态首页的处理方法。通过本文,您将了解如何高效地管理和引用静态资源。 ... [详细]
  • 交互式左右滑动导航菜单设计
    本文介绍了一种使用HTML和JavaScript实现的左右可点击滑动导航菜单的方法,适用于需要展示多个链接或项目的网页布局。 ... [详细]
  • js常用方法(1)startWithJava代码varstartsWithfunction(str,regex){if(regexundefined||strundefined|| ... [详细]
  • 本文档详细介绍了Robot Framework的基础知识、安装配置方法及其实用技巧。从环境搭建到编写第一个测试用例,涵盖了一系列实用的操作指南和最佳实践。 ... [详细]
  • 本文详细介绍如何在Android模拟器上安装TaintDroid的过程,包括解决源代码链接失效及服务器文件变动等问题,旨在帮助后续用户避免不必要的麻烦。 ... [详细]
  • Android 8.1 启动动画 ZIP 包详解
    本文详细解析了 Android 8.1 系统启动动画的 ZIP 包结构,包括其组成文件及配置方法,特别是对 `desc.txt` 文件格式进行了深入说明。 ... [详细]
  • 本文介绍如何在Mac OS X系统上安装和配置Frida工具,以及如何利用该工具在已越狱的iOS设备上进行应用程序的破解。主要内容包括Frida的安装步骤、环境配置、证书验证问题的解决方法等。 ... [详细]
author-avatar
Junjie_Liu85
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有