Type of CSS interface has been changed from function to object

Published: | Categories: CSS, DOM

Description

The CSS interface has internally become a namespace after a discussion in the CSS Working Group. According to the change, typeof CSS now returns "object" instead of "function" so be careful when implementing feature detection with it.

// This will no longer work
if (typeof CSS === 'function' && typeof CSS.supports === 'function') {
  // CSS.supports is available
}

// Do this
if (typeof CSS !== 'undefined' && typeof CSS.supports === 'function')

// or this
if ('CSS' in window && typeof CSS.supports === 'function')

References