问题
Can you advice me how to get Navigator.oscpu using Scala-js? Mapping to native Navigator does not seems to have the oscpu. https://developer.mozilla.org/en-US/docs/Web/API/Navigator/oscpu
回答1:
This appears to be a Firefox-only feature (based on a quick look around), so it's not supported by Scala.js out of the box. You'll need to add it yourself, by adding a side-facade to Navigator. This isn't terribly hard -- see the definition of BeaconNavigator for an example of how to do this.
So you would need something like (untested):
@js.native
trait OSCPUNavigator extends js.Object {
def oscpu: String = js.native
}
implicit def toOSCPUNavigator(n: Navigator): OSCPUNavigator =
n.asInstanceOf[OSCPUNavigator]
Basically, you define a trait with oscpu
on it, and you tell Scala.js how to see a Navigator
as that trait.
Mind, though, it'll still only work on Firefox. I suspect it'll throw errors on other browsers...
来源:https://stackoverflow.com/questions/37398706/scala-js-navigator-oscpu