当我尝试在ace.js中创建Range对象时,会出现“非法构造函数”。引发错误 [英] When I try to create a Range object in ace.js, an "Illegal Constructor" error is thrown
问题描述
我正在尝试在代码中为 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:非法的构造函数
错误。是什么导致此行为,为什么它与文档不匹配?
It raises an Uncaught TypeError: Illegal constructor
error. What is causing this behavior, and why doesn't it match the documentation?
推荐答案
范围
是大多数浏览器无法实例化的本机类型。我对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屋!