Is there a way that I can make this inside elements.heading to refer to page object? I tried get heading but then this only refers to the elements object, Is there a way I can use the getter to refer to the page object.
Yeah the trick is to use the bind() method of functions. You can put this in your init()…
// Bind your heading function to 'this' (the page object at this point in time to your init method)
// and assign it back to the function. Now heading function will use this as the page object.
this.elements.heading = this.elements.heading.bind(this);
I hope this helps. For more information, look up the bind() method for binding different object reference for this.
Before this, I was doing that where all of the items in elements were variables in the forEach function, but I wanted them to all be in a object of their own, so that things were cleaner and I wanted to create a method which allowed new elements to be inserted in the object.