operator

Peter Lee·2020년 5월 1일
0

~/ 연산자

~/ 라는 독특한 연산자가 있다.
자바스크립트에서 나눗셈의 몫을 구하는 방법은 다음과 같다.

Math.floor(5/2); //2

다트에서는 ~/를 사용하면 된다.

print(5~/2); //2

is, as (Type check)

js의 typeof 를 대체한다.

var a = 1;
print (a is String); //false

exp1 ?? exp2

exp1이 null이 아니라면 exp1, exp1이 null 이라면 exp2
다음 두 구문은 같다.

var a = 1;
print(a ?? 2)
var a = 1;
print(a != null ? a : 2);

cascade notation (..)

js에서 버튼을 셀렉트 하고 onclick, text, class.... 하려면 다음과 같을 것이다.

var button = document.querySelector('#button');
button.text = '하이';
button.onClick= function(){
}
...

다트에서는?

document.querySelector('#button') 
..text = '하이'
..onclick = (){}
....

?.

?. 앞의 값이 null 이라면 뒤는 실행되지 않고 null을 뱉는다.

var a = 1;
var b;
print(a?.toString()); //'1'
  print(b?.toString()); // null

0개의 댓글