Skip to content
陈广亮的技术博客
Go back

JS 判断浏览器是否支持严格模式

严格模式中函数内 thisundefined

var hasStrictMode = (function () {
  "use strict";
  return this == undefined;
})();

另外,一个忽略 new 操作符的技巧:

function P() {
  if (!(this instanceof P)) return new P();
}

Share this post on:

Previous Post
ES6 Generator 与 co 模块
Next Post
JS 类型转换:对象转原始值