IE中的LESS会抛出异常(LESS in IE throws exceptions)
我正在使用LESS和respond.js来简化新网站的开发。 LESS和回应都非常简洁。 然而,随着IE中的LESS我遇到了很多问题。
对于IE8模式的初学者,我的IE10报告说id不理解“map”。 没问题,我写了一个Array.prototype映射扩展。 然后它说它不理解isArray,再次处于IE8模式。 原型扩展再次拯救。 现在它回来说一些类似于SyntaxError的内容:'in'的操作数无效:期望的对象
我实际上并不知道可能是什么,但无论如何我不能动态地添加adhoc原型扩展,希望事情最终能够解决。 要么LESS不能用于IE,要么其他人可以指出我需要的所有修复才能使它工作。
I am playing aorund with using LESS along with respond.js to streamline the development of a new site. Both LESS and respond are quite simply neat. However, with LESS in IE I have run into many problems.
For starters in IE8 mode my IE10 reported that id did not understand "map". No problems, I wrote up an Array.prototype map extension. Then it said that it did not understand isArray, once again in IE8 mode. Prototype extensions to the rescue again. Now it comes back saying something along the lines of SyntaxError: Invalid operand to 'in': Object expected
I am not in fact aware of what in might be but in any case I cannot keep adding adhoc prototype extenions on the fly in the hope that things will eventually settle down. Either LESS is unusable with IE or else someone here can point me to all the fixes needed to make it work.
原文:https://stackoverflow.com/questions/18782273
最满意答案
你总是希望在特征中使用
def
或lazy val
(而不是val
)来避免你发现的尴尬行为。至于为什么会在JVM中得到Scala实现的低级细节,请查看Josh Suereth 2012年Scala Days的优秀演讲“Binary Resilience” 。
You always want to use either
def
orlazy val
in traits (rather than justval
) to avoid the awkward behavior you discovered.As for why, which gets to the low-level details of Scala's implementation in the JVM, check out Josh Suereth's excellent talk "Binary Resilience" from Scala Days 2012.
相关问答
更多-
这是一个报告错误 - 你可以在这里投票: https : //youtrack.jetbrains.com/issue/PY-16132 It's a reported bug - you can vote for it here: https://youtrack.jetbrains.com/issue/PY-16132
-
使用N个参数实现def作为FunctionN类型的val(Implementing a def with N parameters as a val of type FunctionN)[2022-01-27]
现在,编辑后,我想我明白你在追求什么。 但是你不能做你想要的,因为类型签名不匹配。 def x: Int = 5 val x: Int = 5 在这两种情况下,您都不提供任何东西并返回Int(在本例中为5)。 大! def expensive(p: Int => Boolean): List[Int] 现在你提供一些东西。 但val只是某处存储的对象。 您可以向标签引用的对象提供某些内容,但这与向标签“x”提供内容不同。 如果你想要val覆盖它,那么你需要使用def: def expensive: (I ... -
def可以由def , val , lazy val或object的任何一个来实现。 所以这是定义成员的最抽象的形式。 由于traits通常是抽象的接口,说你想要一个val是说实现应该怎么做。 如果你要求一个val ,一个实现类不能使用def 。 仅当需要稳定的标识符(例如,依赖于路径的类型)时才需要val 。 这是你通常不需要的东西。 比较: trait Foo { def bar: Int } object F1 extends Foo { def bar = util.Random.nextInt( ...
-
为什么val和def在不同的时间实现抽象方法?(Why do val and def implement abstract methods at different times?)[2023-04-23]
你总是希望在特征中使用def或lazy val (而不是val )来避免你发现的尴尬行为。 至于为什么会在JVM中得到Scala实现的低级细节,请查看Josh Suereth 2012年Scala Days的优秀演讲“Binary Resilience” 。 You always want to use either def or lazy val in traits (rather than just val) to avoid the awkward behavior you discovered. A ... -
以下是代码在初始化MainFoo时尝试执行的MainFoo : 分配一块内存,为val calcNumbers和val numbers提供足够的空间,最初设置为0 。 运行基类Foo的初始化程序,它在初始化calcNumbers时尝试调用numbers.map 。 运行子类MainFoo初始numbers MainFoo ,将numbers初始化为List(1, 2, 3) 。 由于在尝试在val calcNumbers = ...访问numbers尚未初始化numbers ,因此会出现NullPointe ...
-
只需为M创建一个伴随对象,它定义静态值,然后在case类中引用它 object M { val description = "I'm M" } case class M extends A with B { override def description = M.description } 或假设子类型之间的共性 trait Description { val title: String val description = s"I'm ${title}" } object M exten ...
-
因为def声明了一个方法,它由编译器放在类中,所以它一经编译就存在。 为了返回一些东西,一个方法必须运行到它实际返回的东西,所以你的第二个例子没有问题。 val声明一个“不可变值”,虽然它仍然必须初始化,在此之前它保持其类型的默认值 - 在这种情况下,0。这个初始化发生在trait T的构造函数运行之后,除非你改变你的使用早期初始化的示例: val y = new { val x = 42L } with T Because def declares a method, which is put in t ...
-
根据抽象val的成员定义val(Scala bug?)(Defining a val in terms of the member of an abstract val (Scala bug?))[2022-08-28]
当你第一次遇到它时,这会令人困惑,但这是预期的行为。 正常的初始化顺序是首先初始化超级特征中的val。 在您的示例中,这意味着特征A中的val x在匿名子类中的val data之前被初始化,因此导致NullPointer。 如果你想让你的例子工作,你必须使用一个名为“早期定义”的功能(语言规范中的5.1.6)。 在您的具体示例中,这是您需要使用的语法: val a = new { val data = new Object { val x = 42 } } with A 这在初始化A中的val之前 ... -
哈! 在通勤之家看出来:-)。 Scala允许具体类中的val覆盖特征中的def 。 我的特质变成了: trait LabelMethods { def setText(text: String) //... } trait MainView { def someLabel: LabelMethods // Note that this member becomes // a def in this trait... ...
-
你要问的表达方式之间没有显着差异。 val x招致私人领域。 请注意,与vs.map(x => f(x))相比, vs.map(_+10)联函数。 但是你必须在任何情况下创建一个函数对象。 一个名字参数=> X是一个() => X引擎盖下。 从REPL中,使用javap显示代码。 -c代码, -v代表详细。 scala> vs.map(f) res0: List[Int] = List(2, 3, 4, 5, 6, 7, 8, 9, 10, 11) scala> :javap -pv - [snip] ...