Skip to content

๐Ÿ“š WebIDL infrastructure for making JavaScript โ†”๏ธ JavaScript bindings

License

Notifications You must be signed in to change notification settings

web4more/webidl

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

15 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

WebIDL helpers for JavaScript

๐Ÿ“š WebIDL infrastructure for making JavaScript โ†”๏ธ JavaScript bindings

Installation

npm install @webfill/webidl

Usage

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 ๐Ÿฅฉ'