Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ES7 新特性 #12

Open
xrkffgg opened this issue Jan 25, 2021 · 0 comments
Open

ES7 新特性 #12

xrkffgg opened this issue Jan 25, 2021 · 0 comments
Labels

Comments

@xrkffgg
Copy link
Owner

xrkffgg commented Jan 25, 2021

  • Array.prototype.includes
  • 指数函数的中缀表示法

Array.prototype.includes

(() => {
  let arr = [1, 2, 3, NaN];

  if (arr.includes(2)) {
    // 查找2是否存在于arr数组中
    console.log("找到了!");        //>> 找到了!
  }
  if (!arr.includes(2, 3)) {
    // 第二个参数3表示数组下标为3的项,也即第4项开始查找
    console.warn("不存在!");       //>> 不存在!
  }

  // 下面两行说明 incluedes 和 indexOf 的区别
  console.log(arr.includes(NaN));       //true
  console.log(arr.indexOf(NaN) != -1);  //false
})();

指数函数的中缀表示法

  • 中缀表示法比函数表示法更简洁,这使它更可取
  • 方便数学、物理、机器人学等领域的计算
// 用法一:x ** y

let squared = 2 ** 2;   // 等同于: 2 * 2
let cubed = 2 ** 3;     // 等同于: 2 * 2 * 2
// 用法二:x **= y

let a = 2;
a **= 2;    // 等同于: a = a * a;

let b = 3;
b **= 3;    // 等同于: b = b * b * b;
@xrkffgg xrkffgg added the js label Jan 25, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant