首页
学习
活动
专区
圈层
工具
发布
    • 综合排序
    • 最热优先
    • 最新优先
    时间不限
  • 来自专栏前端资源

    JS控制报错:Uncaught SyntaxError: Invalid shorthand property initializer

    JS控制报错:Uncaught SyntaxError: Invalid shorthand property initializer 的解决方法: 今天复制了一串 js 代码,运行发现页面无法正常展示 ,控制台报错:Uncaught SyntaxError: Invalid shorthand property initializer 。

    9.2K20发布于 2020-04-16
  • 来自专栏技术社区

    34种JavaScript简写优化技术,赶紧收藏起来吧

    //Longhand if (x === 'abc' || x === 'def' || x === 'ghi' || x ==='jkl') { //logic } //Shorthand if // Longhand let test: boolean; if (x > 100) { test = true; } else { test = false; } // Shorthand //Longhand let test1; let test2 = 1; //Shorthand let test1, test2 = 1; 4.Null, Undefined,空检查 当我们创建新的变量时 //Longhand let test1, test2, test3; test1 = 1; test2 = 2; test3 = 3; //Shorthand let [test1, test2, // Longhand test1 = test1 + 1; test2 = test2 - 1; test3 = test3 * 20; // Shorthand test1++; test2--;

    35520编辑于 2022-06-16
  • 来自专栏IT大咖说

    2021年要了解的34种JavaScript简写优化技术

    //Longhand if (x === 'abc' || x === 'def' || x === 'ghi' || x ==='jkl') { //logic } //Shorthand if // Longhand let test: boolean; if (x > 100) { test = true; } else { test = false; } // Shorthand == '') { let test2 = test1; } // Shorthand let test2 = test1 || ''; 5.null值检查和分配默认值 let test1 = //Longhand let test1, test2, test3; test1 = 1; test2 = 2; test3 = 3; //Shorthand let [test1, test2 // Longhand test1 = test1 + 1; test2 = test2 - 1; test3 = test3 * 20; // Shorthand test1++; test2--;

    73310发布于 2021-04-23
  • 来自专栏前端达人

    2021年这34个JS优化技巧值得学习下

    //longhand if (x === 'abc' || x === 'def' || x === 'ghi' || x ==='jkl') { //logic } //shorthand if // Longhand let test: boolean; if (x > 100) { test = true; } else { test = false; } // Shorthand //shorthand const welcome = `Hi ${test1} ${test2}`; 21. 跨行字符串 当我们在代码中处理跨行字符串时,可以这样做。 双重按位操作 // Longhand Math.floor(1.9) === 1 // true // Shorthand ~~1.9 === 1 // true 31. 获取字符串的字符 let str = 'abc'; //Longhand str.charAt(2); // c //Shorthand str[2]; // c 34.

    58840发布于 2021-06-16
  • 来自专栏深度学习与python

    20个常用的JavaScript简写技巧

    声明变量 //Longhand let x; let y = 20; //Shorthand let x, y = 20; 2. 给多个变量赋值 我们可以使用数组解构来在一行中给多个变量赋值。 //Longhand let a, b, c; a = 5; b = 8; c = 12; //Shorthand let [a, b, c] = [5, 8, 12]; 3. let x = 'Hello', y = 55; //Longhand const temp = x; x = y; y = temp; //Shorthand [x, y] = [y, x]; 7. //Longhand const power = Math.pow(4, 3); // 64 // Shorthand const power = 4**3; // 64 15. // Shorthand const arr = [2, 8, 15, 4]; Math.max(...arr); // 15 Math.min(...arr); // 2 17.

    1.3K30发布于 2020-12-07
  • 来自专栏前端Q

    34种你需要了解的JavaScript优化技术

    //longhand if (x === 'abc' || x === 'def' || x === 'ghi' || x ==='jkl') { //logic } //shorthand if // Longhand let test: boolean; if (x > 100) { test = true; } else { test = false; } // Shorthand == '') { let test2 = test1; } // Shorthand let test2 = test1 || ''; 5、空值检查和分配默认值 let test1 = null //Longhand let test1, test2, test3; test1 = 1; test2 = 2; test3 = 3; //Shorthand let [test1, test2, // Longhand test1 = test1 + 1; test2 = test2 - 1; test3 = test3 * 20; // Shorthand test1++; test2--;

    1.2K30发布于 2021-04-29
  • 来自专栏Vue中文社区

    34个JavaScript简写优化技术

    //Longhand if (x === 'abc' || x === 'def' || x === 'ghi' || x ==='jkl') { //logic } //Shorthand if // Longhand let test: boolean; if (x > 100) { test = true; } else { test = false; } // Shorthand == '') { let test2 = test1; } // Shorthand let test2 = test1 || ''; 5.null 值检查和分配默认值 let test1 //Longhand let test1, test2, test3; test1 = 1; test2 = 2; test3 = 3; //Shorthand let [test1, test2, // Longhand test1 = test1 + 1; test2 = test2 - 1; test3 = test3 * 20; // Shorthand test1++; test2--;

    1.2K30发布于 2021-07-05
  • 来自专栏java一日一条

    19 个 JavaScript 编码小技巧

    Shorthand: ? 你还可以像下面这样嵌套if语句: ? Shorthand: ? 如果存在 这可能是微不足道的,但值得提及。做“如果检查”时,赋值操作符有时可以省略。 Longhand: ? Shorthand: ? Shorthand: ? ? Shorthand: ? 默认参数值 你可以使用if语句来定义函数参数的默认值。在ES6中,可以在函数声明中定义默认值。 Longhand: ? Shorthand: ? Shorthand: ?

    1K40发布于 2018-09-14
  • 来自专栏前端达人

    33个有用的 JavaScript 小技巧

    //Longhand let data1; let data2= 1; //Shorthand let data1, data2= 1; 4、检查非空值 如果我们想检查变量不为空怎么办? == '') { let data2 = data1; } // Shorthand let data2 = data1 || ''; 5、分配默认值 let data1 = null, // Longhand data1 = data1 + 1; data2 = data2 - 1; data3 = data3 * 30; // Shorthand data1++; data2--; == null) // Shorthand // if (test1) 注意:如果 test1 有任何值,它将落入 if 循环之后的逻辑中,该运算符主要用于 null 或 undefined 检查。 //Longhand if (test1) { callMethod(); } //Shorthand test1 && callMethod(); 12、返回简写 这将有助于避免使用大量代码,

    1.3K10发布于 2021-07-16
  • 来自专栏漫画前端

    如何让小姐姐崇拜你的代码

    ageGroup; // LONG FORM if (age > 18) { ageGroup = "An adult"; } else { ageGroup = "A child"; } // SHORTHAND FORM if(maybeSomething){ console.log(maybeSomething) } else { console.log("Nothing found") } //SHORTHAND 这可以应用于交换两个变量而无需第三个: let x = 1; let y = 2; // LONGER FORM let temp = x; x = y; y = temp; // SHORTHAND nums1 = [1, 2, 3]; const nums2 = [4, 5, 6]; // LONG FORM let newArray = nums1.concat(nums2); // SHORTHAND ; } // LONGER FORM if(isReady){ doSomething(); } // SHORTHAND isReady && doSomething(); 10、类固醇的字符串

    1.7K30发布于 2021-08-25
  • 来自专栏前端达人

    25个实用的JavaScript开发小技巧

    ageGroup; // LONG FORM if (age > 18) { ageGroup = "An adult"; } else { ageGroup = "A child"; } // SHORTHAND FORM if(maybeSomething){ console.log(maybeSomething) } else { console.log("Nothing found") } //SHORTHAND ; 也可以使用此语法代替将值推送到数组: let numbers = [1, 2, 3]; // LONGER FORM numbers.push(4); numbers.push(5); // SHORTHAND ; } // LONGER FORM if(isReady){ doSomething(); } // SHORTHAND isReady && doSomething(); 9、 类固醇的字符串 case 2: someOtherFunction(); break; case 3: yetAnotherFunction(); break; } // SHORTHAND

    1K20发布于 2021-07-16
  • 来自专栏前端达人

    34种你需要了解的JavaScript优化技术

    //longhand if (x === 'abc' || x === 'def' || x === 'ghi' || x ==='jkl') { //logic } //shorthand if // Longhand let test: boolean; if (x > 100) { test = true; } else { test = false; } // Shorthand == '') { let test2 = test1; } // Shorthand let test2 = test1 || ''; 5、空值检查和分配默认值 let test1 = null //Longhand let test1, test2, test3; test1 = 1; test2 = 2; test3 = 3; //Shorthand let [test1, test2, // Longhand test1 = test1 + 1; test2 = test2 - 1; test3 = test3 * 20; // Shorthand test1++; test2--;

    1.3K20发布于 2021-04-22
  • 来自专栏前端达人

    20个让你看起来更加专业的 JavaScript 技巧

    ; let group; // LONG VERSION if (age >= 18) { group = "Adult"; } else { group = "Child"; } // SHORTHAND LONGER EXPRESSION if(someValue){ console.log(someValue) } else { console.log("Nothing found") } //SHORTHAND 例如: let numbers = [1, 2, 3]; // LONGER FORM numbers.push(4); numbers.push(5); // SHORTHAND numbers 例如: let num1, num2; // LONGER FORM num1 = 10; num2 = 100; // SHORTHAND [num1, num2] = [10, 100]; 这也适用于对象 例如: let x = 1; let y = 2; // LONGER FORM let temp = x; x = y; y = temp; // SHORTHAND [x, y] = [y, x

    1.1K20发布于 2021-09-08
  • 来自专栏crossoverJie

    技术阅读周刊第十期

    Golang: 14 Shorthand Tricks You Might Not Know! // Shorthand message := "Hello, Golang!" 声明和初始化多个变量 // Long form var a, b, c int a = 1 b = 2 c = 3 // Shorthand a, b, c := 1, 2 , 3 交换变量 a, b := 1, 2 // Long form temp := a a = b b = temp // Shorthand a, b = b, = nil { // Handle the error } // Shorthand if result, err := someFunction(); err !

    30810编辑于 2023-12-19
  • 来自专栏程序生涯

    15个JavaScript 编码小技巧

    Longhand: const x = 20;let answer;if (x > 10) { answer = 'is greater'; } else { answer = 'is lesser'; } Shorthand == '') { let variable2 = variable1; } Shorthand: const variable2 = variable1 || 'new'; 不要相信我,请先相信自己的测试 Shorthand: let a;if ( !a ) {// do something...} ; } return bar; } Shorthand: mandatory = () => { throw new Error('Missing parameter!') Longhand: Math.floor(4.9) === 4 //true Shorthand: ~~4.9 === 4 //true

    60310发布于 2020-08-14
  • 来自专栏前端达人

    分享 16 个有用的 TypeScript 和 JS 技巧

    == undefined) { finalStr = 'default string' } else { finalStr = str } // Shorthand let str = '' let == undefined) { actualNum = num } else { actualNum = 0 } // Shorthand let num = null let actualNum 例如: // Shorthand const name = 'Iby' const hobby = 'to read' const fullStr = `${name} loves ${hobby}. 请参阅下面的对象属性分配简写示例: // Longhand const obj = { x: 1, y: 2, z: 3 } // Shorthand const x = 8 const } // Shorthand console.log(realNum + (~realNumIndex ? ' exists!' : ' does not exist!')

    1.7K20编辑于 2022-06-09
  • 来自专栏DevOps

    Go:命令行参数解析工具plag简介

    原生支持更丰富的功能:支持 shorthand、deprecated、hidden 等高级功能。 二、实践 1. 标记为即将废弃的,请用户使用 des-detail 的 shorthand 参数 flag.CommandLine.MarkShorthandDeprecated("badflag", "please - 表示 shorthand,-- 表示完整的选项名称。 除了最后一个 shorthand,其它的 shorthand 都必须是布尔类型的参数或者是具有默认值的参数。 通过 MarkDeprecated 和 MarkShorthandDeprecated 方法可以分别把参数及其 shorthand 标记为废弃: // 把 badflag 参数标记为即将废弃的,请用户使用 标记为即将废弃的,请用户使用 des-detail 的 shorthand 参数 flag.CommandLine.MarkShorthandDeprecated("badflag", "please

    45210编辑于 2024-03-29
  • 来自专栏Go与云原生

    强烈反对!群友说 python 写命令行绑定比 go 更方便?

    flag:"name" usage:"student name" persistent:"true"` Age int64 `flag:"age" usage:"student age" shorthand int64 时间: timeDuration, *time.Duration flag 与 cobra 定义一致 func (f *FlagSet) Uint64VarP(p *uint64, name, shorthand string, value uint64, usage string) { f.VarP(newUint64Value(value, p), name, shorthand, usage) } 3 " usage:"student name" persistent:"true"` AgePtr *int64 `flag:"ageptr" usage:"student age" shorthand 连接, --config.password shorthand:"c" : 参数简写 -c, 简写没有潜逃 usage:"comment balalal": 参数说明 persistent : 全局 4

    27510编辑于 2024-04-03
  • 来自专栏Go与云原生

    golang 反射1: 使用反射绑定 cobra flag 参数

    flag 与 cobra 定义一致 func (f *FlagSet) Uint64VarP(p *uint64, name, shorthand string, value uint64, usage string) { f.VarP(newUint64Value(value, p), name, shorthand, usage) } flag 设置 type student struct :"name" usage:"student name" persistent:"true"` Age int64 `flag:"age" usage:"student age" shorthand 连接, --config.password shorthand:"c" : 参数简写 -c, 简写没有潜逃 usage:"comment balalal": 参数说明 persistent : 全局 默认值设置 :"name" usage:"student name" persistent:"true"` Age int64 `flag:"age" usage:"student age" shorthand

    55320编辑于 2022-12-24
  • 来自专栏Go与云原生

    cobrax 使用反射获取 flag 配置, 支持指针字段

    int64时间: timeDuration, *time.Durationflag 与 cobra 定义一致func (f *FlagSet) Uint64VarP(p *uint64, name, shorthand string, value uint64, usage string) { f.VarP(newUint64Value(value, p), name, shorthand, usage)}flag flag:"name" usage:"student name" persistent:"true"` Age int64 `flag:"age" usage:"student age" shorthand nameptr" usage:"student name" persistent:"true"` AgePtr *int64 `flag:"ageptr" usage:"student age" shorthand flag:"name" usage:"student name" persistent:"true"` Age int64 `flag:"age" usage:"student age" shorthand

    52830编辑于 2022-12-14
领券