Cross Browser Valid JavaScript Names

后端 未结 2 1533
长发绾君心
长发绾君心 2020-12-18 15:49

Before you quickly post with \"RTFM\" or with a bunch of links I have visited, I am fully aware of the documented reserved variable names not to use.

The best lists

2条回答
  •  心在旅途
    2020-12-18 16:31

    If you want a big list of browser-defined variables to extend the official list of reserved keywords, type the following into your console on an empty page (about:blank):

    >>> Object.getOwnPropertyNames(window)
    >>> Object.getOwnPropertyNames(Object.getPrototypeOf(window)) // sometimes not Object
    

    which will yield an Array of strings you definitely should not use. It includes "print", too.

    Yet it will be browser-dependent, because some do not implement all the cool HTML5-drafted stuff that uses the Window interface; e.g. you won't find "Worker" in IE9, "openDatabase" in FF and so on. Also, it might not list legacy properties like "onload", altough you will be able to to get a property descriptor for it (and "onload" in window === true).

提交回复
热议问题