php和jq開發怎麼使用es6,PHP與jquery

本文目錄一覽:

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。

原創文章,作者:OFOC,如若轉載,請註明出處:https://www.506064.com/zh-tw/n/137437.html

(0)
打賞 微信掃一掃 微信掃一掃 支付寶掃一掃 支付寶掃一掃
OFOC的頭像OFOC
上一篇 2024-10-04 00:17
下一篇 2024-10-04 00:17

相關推薦

  • PHP和Python哪個好找工作?

    PHP和Python都是非常流行的編程語言,它們被廣泛應用於不同領域的開發中。但是,在考慮擇業方向的時候,很多人都會有一個問題:PHP和Python哪個好找工作?這篇文章將從多個方…

    編程 2025-04-29
  • jQuery Datatable分頁中文

    jQuery Datatable是一個非常流行的數據表插件,它可以幫助您快速地在頁面上創建搜索、過濾、排序和分頁的數據表格。不過,它的默認設置是英文的,今天我們就來探討如何將jQu…

    編程 2025-04-29
  • PHP怎麼接幣

    想要在自己的網站或應用中接受比特幣等加密貨幣的支付,就需要對該加密貨幣擁有一定的了解,並使用對應的API進行開發。本文將從多個方面詳細闡述如何使用PHP接受加密貨幣的支付。 一、環…

    編程 2025-04-29
  • tavjq – jQuery的輕量級替代品

    本文將對tavjq進行詳細的闡述,介紹其基本語法和主要優點。tavjq是一個輕量級的jQuery替代品,它的主要目的是提供一種更快速、更精簡的JavaScript選擇器和DOM操作…

    編程 2025-04-28
  • 使用PHP foreach遍歷有相同屬性的值

    本篇文章將介紹如何使用PHP foreach遍歷具有相同屬性的值,並給出相應的代碼示例。 一、基礎概念 在講解如何使用PHP foreach遍歷有相同屬性的值之前,我們需要先了解幾…

    編程 2025-04-28
  • PHP獲取301跳轉後的地址

    本文將為大家介紹如何使用PHP獲取301跳轉後的地址。301重定向是什麼呢?當我們訪問一個網頁A,但是它已經被遷移到了另一個地址B,此時若伺服器端做了301重定向,那麼你的瀏覽器在…

    編程 2025-04-27
  • PHP登錄頁面代碼實現

    本文將從多個方面詳細闡述如何使用PHP編寫一個簡單的登錄頁面。 1. PHP登錄頁面基本架構 在PHP登錄頁面中,需要包含HTML表單,用戶在表單中輸入賬號密碼等信息,提交表單後服…

    編程 2025-04-27
  • PHP與Python的比較

    本文將會對PHP與Python進行比較和對比分析,包括語法特性、優缺點等方面。幫助讀者更好地理解和使用這兩種語言。 一、語法特性 PHP語法特性: <?php // 簡單的P…

    編程 2025-04-27
  • Jquery獲取ID詳解

    一、從jQuery中獲取ID的值 在前端開發中,獲取DOM的id值是一個非常常見的操作,jQuery為我們提供了非常方便的方法,通過$(“#id”)獲取就可…

    編程 2025-04-25
  • PHP版本管理工具phpenv詳解

    在PHP項目開發過程中,我們可能需要用到不同版本的PHP環境來試驗不同的功能或避免不同版本的兼容性問題。或者我們需要在同一台伺服器上同時運行多個不同版本的PHP語言。但是每次手動安…

    編程 2025-04-24

發表回復

登錄後才能評論