We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
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
function sum(a, b) { return a + b; }
// 可以命名: (function sum(a, b) { return a + b; }); // 也可匿名 (AVOID): (function(a, b) { return a + b; }); // 也能分配给变量: const sum = function sum(a, b) { return a + b; })
// 一般形式: (a, b) => { return a + b }; // 单参数,一行返回: name => name.split(' ') // 多参数,一行返回: (a, b) => a + b // 单参数,带函数体 name => { return name.split(' '); }
function *sum(a, b) { yield a + b; }
async function sum(a, b) { return await a + b; }
new Function(‘a’, ‘b’, ‘return a + b;’);
// 默认导出 export default function(a, b) { return a + b; }; // 命名导出 export function sum(a, b) { return a + b; };
// 一般形式: const object = { sum: function(a, b) { return a + b; }, }; // 简写: const object = { sum(a, b) { return a + b; }, };
const functionName = "sum"; const object = { [functionName]: function(a, b) { return a + b; }, };
// 一般形式: const object = { get answer { return 42; }, set answer(value) { /* 一些操作value的代码 */ }, }; // 使用 defineProperty const obj = {}; Object.defineProperty(obj, "answer", { get() { return 42; }, set(value) { /* 一些操作value的代码 */ }, });
const functionName = "answer"; const object = { get [functionName]() { return 42; }, set [functionName](value) { /* 一些操作value的代码 */ }, };
class Compute { // 一般形式: sum(a, b) { return a + b; } } class Compute { // 静态: static sum(a, b) { return a + b; }; }
class Compute { // 一般形式: sum = function (a, b) { return a + b; }; }class Compute { // 静态: static sum = function(a, b) { return a + b; }; }
class Compute { // 一般形式: #sum(a, b) { return a + b; } // 静态: static #sum(a, b) { return a + b; } }
选自 https://mp.weixin.qq.com/s/qGvaesdpfaI3gr6cp2vNHg
The text was updated successfully, but these errors were encountered:
No branches or pull requests
选自 https://mp.weixin.qq.com/s/qGvaesdpfaI3gr6cp2vNHg
The text was updated successfully, but these errors were encountered: