๐ WebIDL infrastructure for making JavaScript
npm install @webfill/webidl
import { bindInterface, defineOperation, types } from "@webfill/webidl";
class Dog {
bark() {
console.log("woof");
}
eat(food) {
console.log(`eating ${food}`);
}
}
Dog = bindInterface(Dog, "Dog");
defineOperation(Dog.prototype, "bark", [], types.undefined)
defineOperation(Dog.prototype, "eat", [types.DOMString], types.undefined);
const dog = new Dog();
//=> Uncaught TypeError: Illegal constructor
const dog = Object.create(Dog.prototype);
dog.bark();
//=> 'woof'
dog.eat();
//=> Uncaught TypeError: Failed to execute 'eat' on 'Dog': 1 argument required, but only 0 present.
dog.eat("๐ฅฉ");
//=> 'eating ๐ฅฉ'