From 0f8735874f8d6098e532b457e4c355b4af5948c4 Mon Sep 17 00:00:00 2001 From: John Ray Date: Thu, 1 Aug 2019 21:14:12 -0400 Subject: [PATCH] Add constructor The function ElementConstructor is a unique constructor that first calls the superclass (parent class), HTMLElement's, constructor with the context of the new element object, then allows for modification of the new object, the constructor's context. --- my-element.html | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/my-element.html b/my-element.html index 001a698..2bb44f8 100644 --- a/my-element.html +++ b/my-element.html @@ -2,7 +2,16 @@ (function() { // Creates an object based in the HTML Element prototype var element = Object.create(HTMLElement.prototype); - + + + // the function ElementConstructor is a unique constructor that first calls + // the superclass (parent class), HTMLElement's, constructor with + // the context of the new element object, then allows for + // modification of the new object, the constructor's context. + element.prototype.constructor = function ElementConstructor() { + HTMLElement.apply(this, arguments); + // do other stuff with element object on construct invocation + } // Fires when an instance of the element is created element.createdCallback = function() {};