Scala-js - Navigator.oscpu

给你一囗甜甜゛ 提交于 2019-12-12 05:28:14

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!