Subj : Re: Implementing Java Interfaces NOT using Rhino To : Keno Albrecht From : Brendan Eich Date : Wed Jul 14 2004 12:10 pm Keno Albrecht wrote: > // create an array enumeration. > var elements = new Enumeration() { > index: 0, elements: array, > hasMoreElements: function() { > return (this.index < this.elements.length); > }, > nextElement: function() { > return this.elements[this.index++]; > } > }; > That's not JavaScript, not ECMA-262. You can't just write an object initialiser after a new Foo() expression. > exits with "missing ; before statement" (pointing to "new Enumeration() > }", Good, that's the right error message. > while > > // create an array enumeration. > var elements = new Enumeration( { > index: 0, elements: array, > hasMoreElements: function() { > return (this.index < this.elements.length); > }, > nextElement: function() { > return this.elements[this.index++]; > } > }); > > (different braces!) fails with "Java class java.utils.Enumeration is > abstract and therefore may not be instantiated" :-(. All you want is an object that has the right properties to match the interface. You wrote that, in both examples above, when you wrote the object initialiser. So you just need to pass that off to Java as if it were a java.util.Enumeration. Here's where you need a LiveConnect guru. Cc'ing some. /be > > > Well, since this is a really useful feature, I would like to use it > within my code. Any comments? > > Thanks, > Keno .