有没有办法将下面的JavaScript代码编写为单行代码?
this.isContactPage = (window.location.pathname === '/contact');
if (!this.isContactPage) return false;
Run Code Online (Sandbox Code Playgroud)
如果this.isContactPage为真,则该方法继续.
this.isContactPage脚本中的其他位置需要该属性.
return !(this.isContactPage = (window.location.pathname === '/contact'));
Run Code Online (Sandbox Code Playgroud)
另一个例子:
console.log(window.prop); // undefined
console.log(!(window.prop = true) || undefined); // undefined
console.log(!(window.prop = true)); // false
console.log(window.prop); // true
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
87 次 |
| 最近记录: |