ClojureScript和闭包:如何防止属性被闭包重命名 [英] ClojureScript and closure: how to protect attributes from being renamed by closure

查看:74
本文介绍了ClojureScript和闭包:如何防止属性被闭包重命名的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试绘制一些HTML5画布,但遇到了高级编译模式的问题。我想用Mozilla浏览器的 mozDash 属性举例说明(尽管这个问题在属性优化功能上非常通用) https://developer.mozilla.org/zh-CN/docs/Web/API/CanvasRenderingContext2D#Gecko- specific_attributes

I am trying to to some HTML5 canvas drawing and I ran across a problem with the advanced compilation mode. I would like to exemplify this with the mozDash property of Mozilla browsers (although this question is quite generic on the attribute optimization feature) https://developer.mozilla.org/en-US/docs/Web/API/CanvasRenderingContext2D#Gecko-specific_attributes

javascript canvas.mozDash = ... 代码可以表示为[1] (设置!(.- mozDash画布)...)或[2] (设置画布 mozDash ...) in Clojurescript。

The javascript canvas.mozDash = ... code can be expressed as [1] (set! (.-mozDash canvas) ...) or [2] (aset canvas "mozDash" ...) in Clojurescript.

我以前使用过[1],并且在大多数情况下都可以使用,但是使用 mozDash 属性 mozDash 标识符在高级编译结果中消失了。因此,我尝试了[2],似乎 mozDash 标识符是使用 set 变体保留的。

I had used [1] before and it worked in most cases, however with the mozDash attribute the mozDash identifier is gone in the advanced compilation result. Therefore I tried [2] and it seems that the mozDash identifier is retained using the aset variant.

因此,我的问题是:


  • 这是这些符号的有意区别吗?

  • 为什么(.- fillStyle canvas)的行为不同([1]和[2]有效)?

  • Is this an intended difference of these notations?
  • Why is the behaviour different ([1] and [2] work) for (.-fillStyle canvas)?

我有点怀疑标准HTML属性在默认情况下会受到保护,而非标准属性(例如 mozDash

I kind of suspect that standard HTML properties are protected by default while not-standard properties (like mozDash) is not supported.

推荐答案

闭包编译器允许重命名externs中未指定的直接访问的属性。或出口。

The closure compiler is allowed to rename directly accessed attributes that aren't specified in externs or exports.

请参见 https ://developers.google.com/closure/compiler/docs/api-tutorial3#propnames

具体来说,(aset x y z)转换为 x [ y] = z ,可将其最小化,而( set!(.-yx)z)转换为 xy = z ,并且可以最小化,除非将xy指定为extern或导出。

Specifically, (aset x "y" z) translates to x["y"] = z, which is exempt from minimizing, while (set! (.-y x) z) translates to x.y = z and can be minimized unless x.y is specified as extern or exported.

我假设在用于Canvas的externs文件中未指定mozDash属性。

I would assume that the mozDash property isn't specified in the externs file(s) you're using for Canvas.

这篇关于ClojureScript和闭包:如何防止属性被闭包重命名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆