0

Here, it reads, "Therefore, this interface can be obtained by using binding-specific casting methods on an instance of the Node interface."

What does it mean that the interface can be "obtained" by "using the binding-specific casting methods?"

What are "binding specific casting methods?"

I understand that the word "binding" here is referring to a language binding. And, that "casting methods" are specific to the binding. But, it still isn't clear to me what the sentence means.

Practically, I would like to create an instance of an Object that inherits from EventTarget.prototype, and call EventTarget.prototype's addEventListener on it.

I understand that that is not possible. It is discussed here. I think the reason it is not possible may be related to this question.

1 Answers1

0

IDL language bindings.

The link in the post is to a DOM2 specification of an "EventTarget" interface, written in IDL ("Interface Definition Language"). As a definition language, IDL describes what must be provided in a an interface written in a real language such as JavaScript, Java, MicoSoft Visual Basic for applications, or C++ for example.

"this interface can be obtained by using binding-specific casting methods on an instance of the Node interface."

is a technical way of saying "use the methods and properties documented for the language you are using, on a DOM node, rather than the exact wording of the specification provided here. The most binding we are most familiar with in web pages is, of course, for JavaScript. "Casting methods" may refer to how the implementation would automatically perform conversions between programming language and the DOM as required - e.g. converting JavaScript numbers to and from integer representations in some DOM attributes.


EventTargetPrototype

In Firefox this in object in the prototype chain of DOM nodes containing addEventListener and associated functions. Again it Firefox you can access it as

Object.getPrototypeOf( Node.prototype))

and then create an object prototyped on it, using

Object.create(Object.getPrototypeOf( Node.prototype))

This didn't work for dispatching events however. It seems additional support ( perhaps the Node interface as well?) is required. Using a HTMLSpanElement for the target "node object" worked in Firefox for dispatching and listening to an event without adding it to the DOM:

let a = document.createElement("SPAN");
a.addEventListener( "custom", function() {console.log("wow");}, false);
a.dispatchEvent( new CustomEvent("custom"));

Would I use this in production code? Definitely not. Except if thousands had tested it before me, in every browser type I might wish to support!

traktor
  • 17,588
  • 4
  • 32
  • 53