ES2019 ﺖﭙﯾﺮﮑﺳﺍ ﺍﻭﺎﺟ


فهرست مطالب

    نمایش فهرست مطالب

ﺖﭙﯾﺮﮑﺳﺍ ﺍﻭﺎﺟ ﻪﺨﺴﻧ ﻩﺭﺎﻤﺷ

.ES6 (2015) ﻭ ES5 (2009) :ﺪﻧﺍ ﻩﺪﺷ ﯼﺭﺍﺬﮕﻣﺎﻧ ﺩﺍﺪﻋﺍ ﺎﺑ JS ﯽﻤﯾﺪﻗ ﯼﺎﻫ ﻪﺨﺴﻧ

... ،ECMAScript 2016، 2017، 2018، 2019 :ﺪﻧﻮﺷ ﯽﻣ ﯼﺭﺍﺬﮕﻣﺎﻧ ﻝﺎﺳ ﺱﺎﺳﺍ ﺮﺑ ﺎﻫ ﻪﺨﺴﻧ ،2016 ﻝﺎ

ES2019 ﺭﺩ ﺪﯾﺪﺟ ﯼﺎﻫ ﯽﮔﮋﯾﻭ

  • String.trimStart()

  • String.trimEnd()

  • Object.fromEntries

  • ﯼﺭﺎﯿﺘﺧﺍ ﺪﯿﺻ

  • Array.flat()

  • Array.flatMap()

  • Array.Sort ﻩﺪﺷ ﺡﻼﺻﺍ()

  • JSON.stringify() ﻩﺪﺷ ﺮﻈﻧ ﺪﯾﺪﺠﺗ

  • ﺪﻨﺘﺴﻫ ﺯﺎﺠﻣ ﻪﺘﺷﺭ ﯼﺎﺒﻔﻟﺍ ﻑﻭﺮﺣ ﺭﺩ ﻩﺪﻨﻨﮐﺍﺪﺟ ﯼﺎﻫﺩﺎﻤﻧ

  • ()Function.toString ﻩﺪﺷ ﯽﻨﯿﺑﺯﺎﺑ

ﺭﺍﺪﺸﻫ

.ﺪﻨﺘﺴﻫ ﺪﯾﺪﺟ ﺎﺘﺒﺴﻧ ﺎﻫ ﯽﮔﮋﯾﻭ ﻦﯾﺍ

(Polyfill) ﺪﻨﺷﺎﺑ ﻪﺘﺷﺍﺩ ﺯﺎﯿﻧ ﻦﯾﺰﮕﯾﺎﺟ ﺪﮐ ﮏﯾ ﻪﺑ ﺖﺳﺍ ﻦﮑﻤﻣ ﯽﻤﯾﺪﻗ ﯼﺎﻫﺮﮔﺭﻭﺮﻣ


trimStart() ﺖﭙﯾﺮﮑﺳﺍ ﺍﻭﺎﺟ ﻪﺘﺷﺭ

ES2019 ﺵﻭﺭ String trimStart() ﺩﺮﮐ ﻪﻓﺎﺿﺍ ﺖﭙﯾﺮﮑﺳﺍ ﺍﻭﺎﺟ

ﻝﺎﺜﻣ

let text1 = "     Hello World!     ";
let text2 = text1.trimStart();

→ ﺪﯿﻨﮐ ﻥﺎﺤﺘﻣﺍ ﺍﺭ ﻥﺁ ﻥﺎﺗﺩﻮﺧ

<!DOCTYPE html>
<html>
<body>

<h1>JavaScript Strings</h1>
<h2>The trimStart() Method</h2>

<p id="demo"></p>

<script>
let text1 = "     Hello World!     ";
let text2 = text1.trimStart();

document.getElementById("demo").innerHTML =
"Length text1 = " + text1.length + "<br>Length text2 = " + text2.length;
</script>

</body>
</html>

:ﺩﻮﺷﯽﻣ ﯽﻧﺎﺒﯿﺘﺸﭘ ﻥﺭﺪﻣ ﯼﺎﻫﺮﮔﺭﻭﺮﻣ ﻪﻤﻫ ﺭﺩ 2020 ﻪﯾﻮﻧﺍﮊ ﺯﺍ Chrome 66 Edge 79 Firefox 61 Safari 12 Opera 50 Apr 2018 Jan 2020 Jun 2018 Sep 2018 May 2018


trimEnd() ﺖﭙﯾﺮﮑﺳﺍ ﺍﻭﺎﺟ ﻪﺘﺷﺭ

ES2019 ﺵﻭﺭ String trimEnd() ﺩﺮﮐ ﻪﻓﺎﺿﺍ ﺖﭙﯾﺮﮑﺳﺍ ﺍﻭﺎﺟ ﻪ

ﻝﺎﺜﻣ

let text1 = "     Hello World!     ";
let text2 = text1.trimEnd();

→ ﺪﯿﻨﮐ ﻥﺎﺤﺘﻣﺍ ﺍﺭ ﻥﺁ ﻥﺎﺗﺩﻮﺧ

<!DOCTYPE html>
<html>
<body>

<h1>JavaScript Strings</h1>
<h2>The trimEnd() Method</h2>

<p id="demo"></p>

<script>
let text1 = "     Hello World!     ";
let text2 = text1.trimEnd();

document.getElementById("demo").innerHTML =
"Length text1 = " + text1.length + "<br>Length text2 = " + text2.length;
</script>

</body>
</html>

:ﺩﻮﺷ ﯽﻣ ﯽﻧﺎﺒﯿﺘﺸﭘ ﻥﺭﺪﻣ ﯼﺎﻫﺮﮔﺭﻭﺮﻣ ﻪﻤﻫ ﺭﺩ 2020 ﻪﯾﻮﻧﺍﮊ ﺯﺍ trimE

Chrome 66 Edge 79 Firefox 61 Safari 12 Opera 50
Apr 2018 Jan 2020 Jun 2018 Sep 2018 May 2018

()fromEntries ﺖﭙﯾﺮﮑﺳﺍ ﺍﻭﺎﺟ ﯽﺷ

ES2019 ﺵﻭﺭ Object fromEntries() ﺩﺮﮐ ﻪﻓﺎﺿﺍ ﺖﭙﯾﺮﮑﺳﺍ ﺍﻭ

ﻝﺎﺜﻣ

const fruits = [
["apples", 300],
["pears", 900],
["bananas", 500]
];

const myObj = Object.fromEntries(fruits);

→ ﺪﯿﻨﮐ ﻥﺎﺤﺘﻣﺍ ﺍﺭ ﻥﺁ ﻥﺎﺗﺩﻮﺧ

<!DOCTYPE html>
<html>
<body>
<h1>JavaScript Objects</h1>
<h2>The fromEntries() Method</h2>

<p>The number of pears are:</p>
<p id="demo"></p>

<script>
const fruits = [
["apples", 300],
["pears", 900],
["bananas", 500]
];

const myObj = Object.fromEntries(fruits);
document.getElementById("demo").innerHTML = myObj.pears;
</script>

</body>
</html>

:ﺩﻮﺷ ﯽﻣ ﯽﻧﺎﺒﯿﺘﺸﭘ 2020 ﻪﯾﻮﻧﺍﮊ ﺯﺍ ﻥﺭﺪﻣ ﯼﺎﻫﺮﮔﺭﻭﺮﻣ ﻪﻤﻫ ﺭﺩ fromE

Chrome 73 Edge 79 Firefox 63 Safari 12.1 Opera 60
Mar 2019 Jan 2020 Oct 2018 Mar 2019 Apr 2019


ﯼﺭﺎﯿﺘﺧﺍ ﺪﯿﺻ

.ﺪﯿﻨﮐ ﻑﺬﺣ ﺍﺭ catch ﺮﺘﻣﺍﺭﺎﭘ ﺪﯿﻧﺍﻮﺗﯽﻣ ،ﺪﯾﺭﺍﺪﻧ ﺯﺎﯿﻧ ﻥﺁ ﻪﺑ ﺮﮔﺍ ،ES2019 ﺯﺍ

ﻝﺎﺜﻣ

:2019 ﺯﺍ ﻞﺒﻗ

try {
  // code
} catch (err) {
  // code
}

:2019 ﺯﺍ ﺪﻌﺑ

try {
  // code
} catch {
  // code
}

catch binding ﯽﻣ ﯽﻧﺎﺒﯿﺘﺸﭘ ﻥﺭﺪﻣ ﯼﺎﻫﺮﮔﺭﻭﺮﻣ ﻪﻤﻫ ﺭﺩ 2020 ﻪﯾﻮﻧﺍﮊ ﺯﺍ ﯼﺭﺎﯿﺘﺧﺍﺩﻮﺷ:

Chrome 66 Edge 79 Firefox 58 Safari 11.1 Opera 53
Apr 2018 Jan 2020 Jan 2018 Mar 2018 May 2018

()flat ﺖﭙﯾﺮﮑﺳﺍ ﺍﻭﺎﺟ ﻪﯾﺍﺭﺁ

ES2019 ﺪﺘﻣ Array flat() ﺩﺮﮐ ﻪﻓﺎﺿﺍ ﺖﭙﯾﺮﮑﺳﺍ ﺍﻭﺎﺟ ﻪﺑ ﺍﺭ

.ﺪﻨﮐ ﯽﻣ ﺩﺎﺠﯾﺍ ﺪﯾﺪﺟ ﻪﯾﺍﺭﺁ ﮏﯾ ،ﻮﺗ ﺭﺩ ﻮﺗ ﻪﯾﺍﺭﺁ ﮏﯾ ﻥﺩﺮﮐ ﻑﺎﺻ ﺎﺑ

ﻝﺎﺜﻣ

const myArr = [[1,2],[3,4],[5,6]];
const newArr = myArr.flat();

→ ﺪﯿﻨﮐ ﻥﺎﺤﺘﻣﺍ ﺍﺭ ﻥﺁ ﻥﺎﺗﺩﻮﺧ

<!DOCTYPE html>
<html>
<body>
<h1>JavaScript Arrays</h1>
<h2>The flat() Method</h2>

<p id="demo"></p>

<script>
const myArr = [[1,2],[3,4],[5,6]];

const newArr = myArr.flat();
document.getElementById("demo").innerHTML = newArr;
</script>

</body>
</html>

JavaScript Array flat() ﺩﻮﺷ ﯽﻣ ﯽﻧﺎﺒﯿﺘﺸﭘ ﻥﺭﺪﻣ ﯼﺎﻫﺮﮔﺭﻭ

Chrome 69 Edge 79 Firefox 62 Safari 12 Opera 56
Sep 2018 Jan 2020 Sep 2018 Sep 2018 Sep 2018

()flatMap ﺖﭙﯾﺮﮑﺳﺍ ﺍﻭﺎﺟ ﻪﯾﺍﺭﺁ

ES2019 ﺪﺘﻣ Array flatMap() ﺩﺮﮐ ﻪﻓﺎﺿﺍ ﺖﭙﯾﺮﮑﺳﺍ ﺍﻭﺎﺟ ﻪﺑ

.ﺪﻨﮐ ﯽﻣ ﻢﯿﺳﺮﺗ ﺍﺭ ﻪﯾﺍﺭﺁ ﮏﯾ ﺮﺻﺎﻨﻋ ﻪﻤﻫ ﺍﺪﺘﺑﺍ flatMap()

ﻝﺎﺜﻣ

const myArr = [1, 2, 3, 4, 5, 6];
const newArr = myArr.flatMap((x) => x * 2);

→ ﺪﯿﻨﮐ ﻥﺎﺤﺘﻣﺍ ﺍﺭ ﻥﺁ ﻥﺎﺗﺩﻮﺧ

<!DOCTYPE html>
<html>
<body>
<h1>JavaScript Arrays</h1>
<h2>The flatMap() Method</h2>

<p id="demo"></p>

<script>
const myArr = [1, 2, 3, 4, 5,6];
const newArr = myArr.flatMap((x) => x * 2);
document.getElementById("demo").innerHTML = newArr;
</script>

</body>
</html>

()ﺭﺍﺪﯾﺎﭘ ﻪﯾﺍﺭﺁ ﯼﺯﺎﺳ ﺐﺗﺮﻣ

ES2019 ﺵﻭﺭ Array sort() ﺍﺭ ﺩﺮﮐ ﯽﻨﯿﺑﺯﺎﺑ.

.ﺩﺍﺩ ﯽﻣ ﻩﺯﺎﺟﺍ QuickSort ﺪﻨﻧﺎﻣ ﺭﺍﺪﯾﺎﭘﺎﻧ ﯼﺯﺎﺳ ﺐﺗﺮﻣ ﯼﺎﻫ ﻢﺘﯾﺭﻮﮕﻟﺍ ﻪﺑ ﺕﺎﺼﺨﺸﻣ ﻦﯾﺍ ،2019 ﻝﺎﺳ

:ﺪﻨﻨﮐ ﻩﺩﺎﻔﺘﺳﺍ ﺭﺍﺪﯾﺎﭘ ﯼﺯﺎﺳ ﺐﺗﺮﻣ ﻢﺘﯾﺭﻮﮕﻟﺍ ﮏﯾ ﺯﺍ ﺪﯾﺎﺑ ﺎﻫﺮﮔﺭﻭﺮﻣ ،ES2019 ﺯﺍ ﺪﻌﺑ

.ﺪﻨﻨﮐ ﻆﻔﺣ ﺭﺍﺪﻘﻣ ﻥﺎﻤﻫ ﺎﺑ ﺮﺻﺎﻨﻋ ﺮﯾﺎﺳ ﻪﺑ ﺖﺒﺴﻧ ﺍﺭ ﺩﻮﺧ ﯽﺒﺴﻧ ﺖﯿﻌﻗﻮﻣ ﺪﯾﺎﺑ ﺮﺻﺎﻨﻋ ،ﺭﺍﺪﻘﻣ ﮏﯾ ﯼﻭ

ﻝﺎﺜﻣ

const myArr = [
  {name:"X00",price:100 },
  {name:"X01",price:100 },
  {name:"X02",price:100 },
  {name:"X03",price:100 },
  {name:"X04",price:110 },
  {name:"X05",price:110 },
  {name:"X06",price:110 },
  {name:"X07",price:110 }
];

→ ﺪﯿﻨﮐ ﻥﺎﺤﺘﻣﺍ ﺍﺭ ﻥﺁ ﻥﺎﺗﺩﻮﺧ

<!DOCTYPE html>
<html>
<body>
<h1>JavaScript Stable Sort</h1>

<p>From ES2019, browsers must use a stable sorting algorithm.</p>
<p>When sorting elements on a key, the elements must keep their relative position to other objects with the same key.</p>

<p id="demo"></p>

<script>

const myArr = [
  {name:"X00",price:100 },
  {name:"X01",price:100 },
  {name:"X02",price:100 },
  {name:"X03",price:100 },
  {name:"X04",price:110 },
  {name:"X05",price:110 },
  {name:"X06",price:110 },
  {name:"X07",price:110 },
  {name:"X08",price:120 },
  {name:"X09",price:120 },
  {name:"X10",price:120 },
  {name:"X11",price:120 },
  {name:"X12",price:130 },
  {name:"X13",price:130 },
  {name:"X14",price:130 },
  {name:"X15",price:130 },
  {name:"X16",price:140 },
  {name:"X17",price:140 },
  {name:"X18",price:140 },
  {name:"X19",price:140 }
];

myArr.sort( (p1, p2) => {
  if (p1.price < p2.price) return -1;
  if (p1.price > p2.price) return 1;
  return 0;
});

let txt = "";
myArr.forEach(myFunction);

function myFunction(value) {
  txt += value.name + " " + value.price + "<br>"; 
}
document.getElementById("demo").innerHTML = txt;
</script>

</body>
</html>

ﺪﻨﻧﺎﻣ ﯼﺮﮕﯾﺩ ﯽﺒﺴﻧ ﺖﯿﻌﻗﻮﻣ ﺭﺩ ﺎﻫ ﻡﺎﻧ ﺎﺑ ﺖﺴﯿﻧ ﺯﺎﺠﻣ ﻪﺠﯿﺘﻧ ،ﺖﻤﯿﻗ ﺱﺎﺳﺍ ﺮﺑ ﯼﺯﺎﺳ ﺐﺗﺮﻣ ﻡﺎﮕﻨﻫ ،ﻻ

X01 100
X03 100
X00 100
X03 100
X05 110
X04 110
X06 110
X07 110

JSON.stringify() ﻩﺪﺷ ﺮﻈﻧ ﺪﯾﺪﺠﺗ

ES2019 ﺵﻭﺭ JSON stringify() ﺍﺭ ﺩﺮﮐ ﯽﻨﯿﺑﺯﺎﺑ.

.ﺪﻨﮐ ﯼﺪﻨﺑﻪﺘﺷﺭ ﺍﺭ\ﺎﺑ ﻩﺪﺷ ﯼﺭﺍﺬﮔﺪﮐ ﯼﺎﻫﻪﺴﯾﻮﻧ ﺖﺴﻧﺍﻮﺗﯽﻤﻧ JSON ،2019 ﻝﺎﺳ ﺯﺍ

ﻝﺎﺜﻣ

let text = JSON.stringify("\u26D4");

→ ﺪﯿﻨﮐ ﻥﺎﺤﺘﻣﺍ ﺍﺭ ﻥﺁ ﻥﺎﺗﺩﻮﺧ

<!DOCTYPE html>
<html>
<body>
<h1>JavaScript JSON</h1>
<h2>Revised stringify()</h2>

<p id="demo"></p>

<script>
let text = JSON.stringify("\u26D4");
document.getElementById("demo").innerHTML = JSON.parse(text);
</script>

</body>
</html>

(U+DFFF ﺎﺗ U+D800) UTF-8 ﺪﮐ ﻁﺎﻘﻧ ﺭﺩ code class="w3-codespan">JSON.stringify()J

،ﺪﻧﻮﺷﯽﻣ ﻞﯾﺪﺒﺗ JSON.stringify() ﺎﺑ ﻦﻤﯾﺍ ﺭﻮﻃ

:ﺪﺷﯽﻣ ﺎﻄﺧ ﺕﺎﺋﺎﻨﺜﺘﺳﺍ ﻪﺑ ﺮﺠﻨﻣ ﻭ ﺪﺷﯽﻣ ﻪﺘﻓﺮﮔ ﺮﻈﻧ ﺭﺩ ﻂﺧ ﻩﺪﻨﻫﺩﻥﺎﯾﺎﭘ ﻥﺍﻮﻨﻋu20

ﻝﺎﺜﻣ

// This is valid in ES2019:
let text = "\u2028";

→ ﺪﯿﻨﮐ ﻥﺎﺤﺘﻣﺍ ﺍﺭ ﻥﺁ ﻥﺎﺗﺩﻮﺧ

<!DOCTYPE html>
<html>
<body>
<h1>JavaScript Strings</h1>

<p>From ES2019, line and paragraph separator symbols (\u2028 and \u2029) are allowed in string literals:</p>

<p id="demo"></p>

<script>
let text = "\u2028";
document.getElementById("demo").innerHTML = text;
</script>

</body>
</html>

ﺪﯿﺷﺎﺑ ﻪﺘﺷﺍﺩ ﻪﺟﻮﺗ

.ﺪﻧﺭﺍﺩ ﯼﻭﺎﺴﻣ ﻦﯿﻧﺍﻮﻗ JSON ﻭ ﺖﭙﯾﺮﮑﺳﺍ ﺍﻭﺎﺟ ،ﻥﻮﻨﮐﺍ

:ES2019 ﺯﺍ ﻞﺒﻗ

text=JSON.parse('"\u2028"') ﺩﻮﺷ ﯽﻣ ﻪﯾﺰﺠﺗ '' ﻪﺑ.

text='"\u2028"' ﻮﺤﻧ ﯼﺎﻄﺧ ﺪﻫﺩ ﯽﻣ.


()toString ﻩﺪﺷ ﺡﻼﺻﺍ ﻊﺑﺎﺗ

ES2019 ﻊﺑﺎﺗ ﺵﻭﺭ toString() ﺍﺭ ﺩﺮﮐ ﯽﻨﯿﺑﺯﺎﺑ.

.ﺖﺳﺍ ﻊﺑﺎﺗ ﮏﯾ ﻊﺒﻨﻣ ﺪﮐ ﻩﺪﻨﻫﺩ ﻥﺎﺸﻧ ﻪﮐ ﺪﻧﺍﺩﺮﮔ ﯽﻣﺮﺑ ﺍﺭ ﯼﺍ ﻪﺘﺷﺭ t

.ﺪﻧﺍﺩﺮﮔﺮﺑ ﺍﺭ ﺕﺍﺮﻈﻧ ﻞﻣﺎﺷ ﻊﺑﺎﺗ ﻊﺒﻨﻣ ﺪﮐ ﺪﯾﺎﺑ()toString ،2019 ﻝﺎﺳ ﺯﺍ

.(ﻪﻠﺻﺎﻓ ﻭ ﺮﻈﻧ ﻥﻭﺪﺑ ﺪﻨﻧﺎﻣ) ﺪﻧﺪﻧﺍﺩﺮﮔﺮﺑ ﺍﺭ ﺩﺮﮑﻠﻤﻋ ﺯﺍ ﯽﻔﻠﺘﺨﻣ ﻉﺍﻮﻧﺍ ﻒﻠﺘﺨﻣ ﯼﺎﻫﺮﮔﺭﻭﺮﻣ ،2019

ﻝﺎﺜﻣ

function myFunction(p1, p2) {
    return p1 * p2;
}

→ ﺪﯿﻨﮐ ﻥﺎﺤﺘﻣﺍ ﺍﺭ ﻥﺁ ﻥﺎﺗﺩﻮﺧ

<!DOCTYPE html>
<html>
<body>

<h1>JavaScript Functions</h1>
<h2>The toString() Method</h2>

<p>The toString() method returns the function as a string:</p>

<p id="demo"></p>

<script>
function myFunction(a, b) {
  return a * b;
}
document.getElementById("demo").innerHTML = myFunction.toString();
</script>

</body>
</html>

تمامی حقوق محفوظ است. © BasicIT.org • 2023-2024