I’m working on implementing pinch zoom-in/out code.
I simply checked WinJS semantic zoom implementation
and found interesting code snippet.
Windows Library for JavaScript 1.0/js/ui.js
Line number: 30710, 30720
return {
x: +ev.clientX === ev.clientX ? (ev.clientX - sezoBox.left - sezoPaddingLeft - sezoBorderLeft) : 0,
y: +ev.clientY === ev.clientY ? (ev.clientY - sezoBox.top - sezoPaddingTop - sezoPaddingTop) : 0
};
Why there is +ev.clientX === ev.clientX?
The unary
+operator is used as a cast to aNumber. It’s a really obscure way of ensuringev.clientXis a number.My recommendation: don’t use it.
I guess this guy really likes his one-liners. I doubt his colleagues agree with him.