RE: Faking host objects


The problem with your code is that the instances don’t really inherit from the exposed prototype:

 

    // let fooInstance be an instance of Foo, got somehow from your API

    Foo.prototype.test2=Foo.prototype.test;

    fooInstance.test2(); // fail

 

I’m pretty sure there’s a good reason, but why don’t you use the straigforward approach (aka: window.publicFoo = function() { ... }; window.Foo.prototype := privateFoo.prototype) ?

 

 

 


De : Marcos Caceres
Envoyé : ‎28‎ ‎décembre‎ ‎2012 ‎23‎:‎08
À : &lt,public-nextweb@w3.org&gt,
Objet : Faking host objects



Hi,  
Sorry I've been a bit off the grid. I've been working on implementing some more of the Web IDL spec while working through the Web MIDI API.  

Anyway, I think I finally figured out the code that replicates host objects in the browser:
https://gist.github.com/4402084


This means that it's not trivial to take some WebIDL and get it exposed in the browser. As in:

interface FooBar(){
readonly attribute DOMString foo;

}  

It would be great if you guys can take a look.  

The code does not yet support constructors, e.g.:  

var x = window.FooBar("foo");  

I'll work on adding that soon.  

With regards to WebIDL, the Web MIDI API gave me an opportunity to implement "toOctet()", which converts an input into an number between 0-255. Not super useful, but…  

Kind regards,
Marcos  
--  
Marcos Caceres

Received on Saturday, 29 December 2012 16:05:14 UTC