When you need use the JS new
operator, use bs.new
.
For example:
type t;
[@bs.new] external createDate: unit => t = "Date";
let date = createDate();
compiles to:
var date = new Date();
When the object is not available on the global scope and needs importing, add bs.module
:
type t;
[@bs.module] [@bs.new] external book: unit => t = "Book";
let myBook = book();
compiles to:
var Book = require("Book");
var myBook = new Book();