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

函数return 一个赋值语句 #9

Open
BlackStar0313 opened this issue Feb 8, 2017 · 0 comments
Open

函数return 一个赋值语句 #9

BlackStar0313 opened this issue Feb 8, 2017 · 0 comments

Comments

@BlackStar0313
Copy link
Owner

BlackStar0313 commented Feb 8, 2017

测试代码如下

` 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 (地址拷贝到浏览器)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant