Skip to content

Instantly share code, notes, and snippets.

@twopoint718
Created July 8, 2018 03:09
Show Gist options
  • Select an option

  • Save twopoint718/215bb0ba8b734fc7cfe6bf8a05eb1059 to your computer and use it in GitHub Desktop.

Select an option

Save twopoint718/215bb0ba8b734fc7cfe6bf8a05eb1059 to your computer and use it in GitHub Desktop.
Objects two ways
// Generated by BUCKLESCRIPT VERSION 3.1.5, PLEASE EDIT WITH CARE
'use strict';
var CamlinternalOO = require("bs-platform/lib/js/camlinternalOO.js");
var shared = [
"name",
"age"
];
var $$class = CamlinternalOO.create_table(shared);
var ids = CamlinternalOO.get_method_labels($$class, shared);
var name = ids[0];
var age = ids[1];
CamlinternalOO.set_methods($$class, /* array */[
name,
(function () {
return "Chris";
}),
age,
(function () {
return 36;
})
]);
CamlinternalOO.init_class($$class);
var chris1 = CamlinternalOO.create_object_opt(0, $$class);
var chris2 = {
name: "Chris2",
age: 36,
job: "Crafter"
};
exports.chris1 = chris1;
exports.chris2 = chris2;
/* class Not a pure module */
type person1('a) =
{
..
name: string,
age: int,
} as 'a;
let chris1:
person1({
.
name: string,
age: int,
}) = {
pub name = "Chris";
pub age = 36
};
[@bs.deriving abstract]
type person2 = {
name: string,
age: int,
job: string,
};
let chris2 = person2(~name="Chris2", ~age=36, ~job="Crafter");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment