github记录
测试代码如下
` public main(): void
let test: boolean = this.test() ;
console.log(“test ” + test + ” param ” + this.m_testNum + ” param2 ” + this.m_testNum2 + ” dadafdfaf ” + (this.m_testNum = false));
if (this.m_testNum = false) {
console.log(“fucking”);
}
console.log(“~~~~”);
}
private test(): boolean {
return this.m_testNum = this.m_testNum2 = false ;
}
private test1(): boolean {
return true ;
}`
return this.m_testNum = this.m_testNum2 = false ;
主要是这句话,在新同学代码review时候,看到有这么用的,奇怪为什么这么用。
测试后,我认为,等号操作符,应该在typeScript和c/c++中意思是一样的,多个等号,按从右到左的顺序进行,然后将最右边等号的右值付给左值,然后左值再作为右边第二个的右值,复制给左值。直到最左边,赋值完成,将变量赋值给 return 的值。
if (this.m_testNum = false)
这种也是赋值语句执行完后,将变量返回到判断语句当中
关于操作符优先级,和操作符结合性的解释:
看
https://developer.mozilla.org/zh-CN/docs/Web/JavaScript/Reference/Operators/Operator_Precedence (地址拷贝到浏览器)