当我尝试在 ace.js 中创建 Range 对象时,会出现“非法构造函数".错误被抛出 [英] When I try to create a Range object in ace.js, an "Illegal Constructor" error is thrown

查看:12
本文介绍了当我尝试在 ace.js 中创建 Range 对象时,会出现“非法构造函数".错误被抛出的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在我的代码中为 ace.js 编辑器创建一个 Range 对象,但它不起作用.它以我无法弄清楚的方式失败.在Ace 文档中,这个构造函数是:

I am trying to create a Range object for the ace.js editor in my code, but it's not working. It is failing in a way I can't figure out. In the Ace documentation, this constructor is:

new Range(Number startRow,
          Number startColumn,
          Number endRow,
          Number endColumn)

但是当我在我的代码中尝试这个时:

But when I try this in my code:

new Range(0, 0, 0, 1)

它会引发一个 Uncaught TypeError: Illegal constructor 错误.是什么导致了这种行为,为什么它与文档不匹配?

It raises an Uncaught TypeError: Illegal constructor error. What is causing this behavior, and why doesn't it match the documentation?

推荐答案

Range 是大多数浏览器无法实例化的原生类型.我对 Ace 不是很熟悉,但我猜他们使用了某种命名空间,以便您可以执行诸如 new Ace.Range() 之类的操作.

Range is a native type is most browsers that you cannot instantiate. I'm not really familiar with Ace, but I'm guessing that they use some sort of namespacing so that you will do something like new Ace.Range().

看起来他们正在使用 CommonJS,因此您可以根据需要导入该方法并为其设置别名:

It looks like they are using CommonJS, so you can import the method and alias it however you like:

var Range = require('ace/range').Range,
    mine = new Range(0,0,10,0);

这篇关于当我尝试在 ace.js 中创建 Range 对象时,会出现“非法构造函数".错误被抛出的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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