回答編集履歴
3
typo修正 \+ Babel
answer
CHANGED
@@ -26,8 +26,8 @@
|
|
26
26
|
拡張子は `URL#pathname` を正規表現で切り出す事で得る事が可能です。
|
27
27
|
|
28
28
|
`URLSearchParams` は iterable なのでスプレッド要素(SpreadElement)で配列化すれば要素数を得られます。
|
29
|
-
SpreadElement は多くのサイトでスプレッド演算子(spread operator)と説明されていますが、厳密には演算子に分類されません。
|
29
|
+
(SpreadElement は多くのサイトでスプレッド演算子(spread operator)と説明されていますが、厳密には演算子に分類されません。)
|
30
|
-
ただし、SpreadElement は IE11- が未対応なので、IE11- が対象ブラウザに含まれる
|
30
|
+
ただし、SpreadElement は IE11- が未対応なので、IE11- が対象ブラウザに含まれるのなら、Babel 等のトランスコンパイラを使うか、Polyfill の機能に準じて下さい。
|
31
31
|
|
32
32
|
- [spread (...) operator - ECMAScript 6 compatibility table](http://kangax.github.io/compat-table/es6/#test-spread_(...)_operator)
|
33
33
|
- [12.2.5Array Initializer - ECMAScript® 2016 Language Specification](http://www.ecma-international.org/ecma-262/7.0/#sec-array-initializer)
|
2
GET パラメータの数を得る
answer
CHANGED
@@ -1,8 +1,9 @@
|
|
1
1
|
### URL Standard
|
2
2
|
|
3
|
-
ただし、IE11- は未対応。
|
3
|
+
ただし、IE11- は未対応なので、Polyfill を適用する必要があります。
|
4
4
|
|
5
|
-
- [URL Standard (日本語訳)](https://triple-underscore.github.io/URL-ja.html)
|
5
|
+
- [6.1. URL class - URL Standard (日本語訳)](https://triple-underscore.github.io/URL-ja.html#url-class)
|
6
|
+
- [6.2. URLSearchParams class - URL Standard (日本語訳)](https://triple-underscore.github.io/URL-ja.html#interface-urlsearchparams)
|
6
7
|
- [URL API - Can I use...](http://caniuse.com/#feat=url)
|
7
8
|
- [URLSearchParams - Can I use...](http://caniuse.com/#feat=urlsearchparams)
|
8
9
|
|
@@ -18,6 +19,25 @@
|
|
18
19
|
console.log(url2.toString()); // http://example.com/sample.html?a=1&b=2
|
19
20
|
```
|
20
21
|
|
22
|
+
### GET パラメータの数を得る
|
23
|
+
|
24
|
+
> 拡張子だけで判断してhtml,phpという拡張子が付いてるときは?で&を2個以上含んでる時のURLは何も処理をしないJavaScriptの書き方は出来ますでしょうか?
|
25
|
+
|
26
|
+
拡張子は `URL#pathname` を正規表現で切り出す事で得る事が可能です。
|
27
|
+
|
28
|
+
`URLSearchParams` は iterable なのでスプレッド要素(SpreadElement)で配列化すれば要素数を得られます。
|
29
|
+
SpreadElement は多くのサイトでスプレッド演算子(spread operator)と説明されていますが、厳密には演算子に分類されません。
|
30
|
+
ただし、SpreadElement は IE11- が未対応なので、IE11- が対象ブラウザに含まれるるのなら、Polyfill の機能に準じて下さい。
|
31
|
+
|
32
|
+
- [spread (...) operator - ECMAScript 6 compatibility table](http://kangax.github.io/compat-table/es6/#test-spread_(...)_operator)
|
33
|
+
- [12.2.5Array Initializer - ECMAScript® 2016 Language Specification](http://www.ecma-international.org/ecma-262/7.0/#sec-array-initializer)
|
34
|
+
|
35
|
+
```JavaScript
|
36
|
+
var url3 = new URL('http://example.com/sample.html?a=1&b=2&c=3#d=4&e=5');
|
37
|
+
console.log(url3.pathname); // "/sample.html"
|
38
|
+
console.log([...url3.searchParams].length); // 3
|
39
|
+
```
|
40
|
+
|
21
41
|
### Polyfill
|
22
42
|
|
23
43
|
- [url polyfill - Google 検索](https://www.google.co.jp/search?q=url+polyfill)
|
1
Polyfill
answer
CHANGED
@@ -1,8 +1,13 @@
|
|
1
1
|
### URL Standard
|
2
2
|
|
3
|
+
ただし、IE11- は未対応。
|
4
|
+
|
3
5
|
- [URL Standard (日本語訳)](https://triple-underscore.github.io/URL-ja.html)
|
6
|
+
- [URL API - Can I use...](http://caniuse.com/#feat=url)
|
7
|
+
- [URLSearchParams - Can I use...](http://caniuse.com/#feat=urlsearchparams)
|
4
8
|
|
5
9
|
```JavaScript
|
10
|
+
|
6
11
|
'use strict';
|
7
12
|
var url1 = new URL('http://example.com/sample.html');
|
8
13
|
url1.searchParams.append('a', 1);
|
@@ -13,4 +18,8 @@
|
|
13
18
|
console.log(url2.toString()); // http://example.com/sample.html?a=1&b=2
|
14
19
|
```
|
15
20
|
|
21
|
+
### Polyfill
|
22
|
+
|
23
|
+
- [url polyfill - Google 検索](https://www.google.co.jp/search?q=url+polyfill)
|
24
|
+
|
16
25
|
Re: satoru32 さん
|