void(document.body.innerText += 'hi')
eval(document.body.innerText +='\nbye')
Function(document.body.innerText += '\n!!!')
void(Function(function foo(){document.body.innerText += '\n>hi2'; return true}).toString())();
eval(Function(function foo(){document.body.innerText += '\nbye2'; return true}).toString())();
Function(Function(function foo(){document.body.innerText += '\n!!!2'; return true}).toString())();Run Code Online (Sandbox Code Playgroud)
在这些不同的语句中执行代码的处理模型是什么?
void(alert('hi'))
undefined
eval(alert('hi'))
undefined
Function(alert('hi'))
function anonymous() {
undefined
}
eval(Function(function foo(){return true}).toString())();
TypeError: undefined is not a function
void(Function(function foo(){return true}).toString())();
TypeError: string is not a function
Function(Function(function foo(){return true}).toString())();
undefined
Run Code Online (Sandbox Code Playgroud) 我已经实现了一些模块,其简化代码如下所示:
(function() {
var context = {...}; // an object which serves as the context for the expression being evaluated
with (context) {
var x = eval(expression);
...
}
}());
Run Code Online (Sandbox Code Playgroud)
澄清一下,我可以完全控制表达式和动态创建的上下文对象。Expression 始终是安全的,并且由受信任的来源提供。表达式中出现的所有成员(字段和函数)始终存在于上下文对象中,例如
var context = {
Concat: function(strA, strB) { return [strA, strB].join(''); },
Name: 'ABC',
Surname: 'DEF'
}
with (context) {
var x = eval("Concat(Name, Surname) == 'XYZ'"); // evaluates to false
...
}
Run Code Online (Sandbox Code Playgroud)
现在,我想将'use strict';pragma 作为模块的第一行插入(假设出于某些原因,我希望整个模块都这样做,我不想对缩小的函数范围集应用严格性并将严格代码与草率混合本模块中的一个)。
因此,我需要更改代码以通过严格模式要求,因为正如 ECMAScript 5.1 规范中所述,严格模式下不允许使用 with语句。
我通过进行以下修改来勒索兼容性来破解这个问题: …
我正在尝试使用 react.js。我在阅读“开始使用 react”时发现了一个问题。(链接:https : //facebook.github.io/react/docs/getting-started.html)
页面中间,有一个声明,
注意:如果您使用的是 ES2015,您还需要使用 babel-preset-es2015 包。
但是,我不知道如何找到我正在使用的那个。我怎么能找到我正在使用的哪一个?
SUM >> 我怎么知道ES版本?
我有一些文件将用 Babel 处理,因此是用 ES6 编写的。但是,我也有一些文件不会通过 Babel,因此应该在同一个项目中的 ES5 中。如果我不小心在这些文件中使用了某些 ES6 特性(例如箭头函数、解构),我可以配置 Eslint 使其抛出错误吗?
我注意到,该设置"parserOptions": {"ecmaVersion": 5}并没有提供理想的效果以及设置"env": {"es6": false}。
我有一个在 Chrome/Firefox 上运行良好的箭头函数,但我也需要它在 IE11 上运行,我不知道还能做什么。
在这里您可以看到 IE11 不支持箭头函数,因此我尝试将我的代码从 ES6 更改为 ES5 ,因为我读到这样做可以解决问题(在链接上您还可以检查我的代码:)去除箭头函数。
也不支持 Object.entries,我仍然需要它。 https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Objects/Object/entries
所以我尝试使用上面链接的 polyfill,但它使用了也不支持的 Reflect。 https://developer.mozilla.org/es/docs/Web/JavaScript/Reference/Global_Objects/Reflect
有任何想法吗?我真的迷失了 IE11 开发。PD:代码仍在 Chrome/Firefox 上运行。
我正在将一个项目从 Angular JS 升级到 Angular 4。TypeScript 已经在 Angular JS 项目中使用,在转换它之后,我在 Visual Studio 中遇到了数以千计的错误,用于 3rd 方打字稿输入文件 (*.d.ts) . 我还在 Visual Studio 中的实际 TypeScript 文件中遇到了一些错误。
当我使用命令行 TypeScript 编译器 (tsc) 时,TypeScript 代码编译成功,所以我想阻止对所有 *.d.ts 文件的编译检查。
我已经查看了非常相似的问题的答案,这些问题建议如何忽略这些错误,但是它们中没有一个对我有用,而且大多数都与 VS 2017 相关。
这是我尝试过的禁用编译检查的方法:
向 .csproj 文件添加了“TypeScriptCompileBlocked”:
<PropertyGroup>
<TypeScriptCompileBlocked>true</TypeScriptCompileBlocked>
....
</PropertyGroup>
Run Code Online (Sandbox Code Playgroud)
添加了 .eslintignore 文件
我已将 .eslintignore 文件添加到项目根目录,并设置忽略所有 *.d.ts 文件:
**/*.d.ts
**/node_modules/*
Run Code Online (Sandbox Code Playgroud)
禁用 ESLint
在 VS 工具 > 选项下,我寻找了一个选项,但在 VS2015 中没有选项可以执行此操作
tsconfig.json - 排除 node_modules 文件夹
"exclude": [
"./node_modules/*"
]
-- I've also tried --
"node_modules"
... and …Run Code Online (Sandbox Code Playgroud) 我的一位同事写了ES6代码......
return map(orderedContentUuids, contentUuid => { uuid: contentUuid });
你可能猜到他打算返回对象{uuid: contentUuid },但由于它是一个箭头函数,花括号{实际上会启动一个新的块.(正确的代码是return map(orderedContentUuids, contentUuid => ({ uuid: contentUuid }));).
但是,出乎意料的是,此代码转换并运行没有错误.没有错误,因为uuid: contentUuid似乎评估contentUuid.
您可以看到,如果您放入JavaScript控制台,foo: 'bar'它将评估为"bar".
咦?这是怎么回事.从什么时候开始就是有效的JS?
我有一些代码可以计算循环中哈希中键/值的总和.它似乎是在ios9 Safari上以不同的方式计算总和,与其他任何地方相比.虽然我可以找到一种方法来修复这个单独的用例,但是我们在整个大型代码库中都使用了这种语法,所以我正在寻找一些理解
__ob__在其上有Vue 对象的所有对象.试试这里的代码:https://liveweave.com/kKo88G.我也粘贴在下面:
// Define a hash
var totalItems, sum, type, value
totalItems = {}
totalItems['0'] = 3
// This definition of __ob__ is done dynamically by Vue,
// but I include it here by way of example of what breaks in ios9
totalItems.__ob__ = new Object()
Object.defineProperty(totalItems, '__ob__', {
enumerable: false,
writable: true,
configurable: true
});
// Loop through the hash
sum = 0
for (type in totalItems) {
value …Run Code Online (Sandbox Code Playgroud) 我一直在尝试使用 Angular Elements 并试图实现最佳的浏览器兼容性。但是我似乎遇到了死胡同,因为当我为 Shadow DOM 添加一个 IE polyfill 时,它破坏了 chrome 中的元素。
最初我遇到了错误“无法构建 HTML 元素”,因此我将 tsconfig.json 中的“目标”更改为 es2015/es6。
配置文件
{
"compileOnSave": false,
"compilerOptions": {
"baseUrl": "./",
"outDir": "./dist/out-tsc",
"sourceMap": true,
"declaration": false,
"module": "es2015",
"moduleResolution": "node",
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"target": "es5",
"typeRoots": [
"node_modules/@types"
],
"lib": [
"es2018",
"dom"
]
}
}
Run Code Online (Sandbox Code Playgroud)
成分
// @dynamic
@Component({
selector: 'flexybox-cardmanagement',
templateUrl: './card-management.component.html',
styleUrls: ['./card-management.component.scss'],
encapsulation: ViewEncapsulation.ShadowDom
})
Run Code Online (Sandbox Code Playgroud)
更改目标碰巧破坏了 IE,因为不支持 es2015/es6+。所以我碰巧在@webcomponents 包中找到了 custom-elements-es5-adapter,它包装了 ES5,为需要它的浏览器提供必要的 ES6 功能。然后我还必须添加对自定义元素的支持。
polyfills.ts
/*****************************************************************************************
* APPLICATION …Run Code Online (Sandbox Code Playgroud) ecmascript-5 polyfills ecmascript-6 angular angular-elements
ecmascript-5 ×10
javascript ×7
ecmascript-6 ×5
eval ×2
angular ×1
babeljs ×1
eslint ×1
ios9 ×1
polyfills ×1
reactjs ×1
strict ×1
syntax ×1
typescript ×1
void ×1
vue.js ×1