Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

When I try to create a Range object in ace.js, an "Illegal Constructor" error is thrown

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)

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

like image 860
Andrés Avatar asked May 04 '12 16:05

Andrés


3 Answers

This worked for me:

import { Range } from "ace-builds"

like image 199
Ferus Avatar answered Nov 15 '22 17:11

Ferus


Replace require('ace/range').Range with ace.require('ace/range').Range

like image 34
ANUSHA E Avatar answered Nov 15 '22 16:11

ANUSHA E


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().

Edit: 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);
like image 39
Prestaul Avatar answered Nov 15 '22 18:11

Prestaul