在最新的chrome中测试时,ES6类中的getter是不可枚举的。
class Foo {
get name() { return 'name'; }
}
// => {get: f, set: undefined, enumerable: false, configurable: true}
Object.getOwnPropertyDescriptor(Foo.prototype, 'name'); 但是,当使用闭包编译器将此代码编译为ES5时,getter属性将变为可枚举的。
npx google-closure-compiler --js=script.js --js_output_file=out.js
var $jscomp=$jscomp||{};$jscomp.scope={};$jscomp.getGlobal=function(a){return"undefined"!=typeof window&&window===a?a:"undefined"!=typeof global&&null!=global?global:a};$jscomp.global=$jscomp.getGlobal(this);var Foo=function(){};$jscomp.global.Object.defineProperties(Foo.prototype,{name:{configurable:!0,enumerable:!0,get:function(){return"name"}}});突出重要的部分:
$jscomp.global.Object.defineProperties(Foo.prototype, {
name: {
configurable:!0,
enumerable:!0,
get:function(){
return"name"
}
}
})这是一个bug,还是闭包编译器显式地使其生成不同结果的原因?
发布于 2019-08-07 03:42:54
这似乎已经在一个2015 bug report中被覆盖了,“已传输的ES6 getters / setters占用了很多空间(&不应该是可枚举的)”,但是线程结束时这个问题显然已经解决并关闭了(“我假设我们可以关闭它”)。
这看起来像是那个bug的回归(如果它真的曾经在第一个地方被修复过),你可以提交一个新的bug来引起开发人员的注意。
https://stackoverflow.com/questions/57382479
复制相似问题