foo in bar - 'in' operator javascript?

前端 未结 4 2218
庸人自扰
庸人自扰 2021-01-21 09:52

I recently read a tutorial on CSS browser feature detection... The end product was something like this...

var prefix = [\'Moz\', \'webkit\', \'O\', \'ms\', \'Kht         


        
4条回答
  •  情深已故
    2021-01-21 10:48

    The in operator is used to check for the presence of a key in an array or object, e.g.

    3 in [1, 2, 3] // false, since the array indices only go up to 2
    2 in [1, 2, 3] // true
    'x' in { x: 5 } // true
    'toString' in Object.prototype // true
    

    The style property there is an instance of CSSStyleDeclaration, which contains properties for each supported style attribute in the active browser.

    The code snippet you gave in your post checks whether the viewing browser supports some version of that style (either the official one or with one of a number of common vendor prefixes).

提交回复
热议问题