Skip to content

Latest commit

 

History

History
34 lines (23 loc) · 505 Bytes

bs.new.md

File metadata and controls

34 lines (23 loc) · 505 Bytes

[@bs.new]

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