There are several different ways of adding methods depending on whether we want the methods to be specific to that object or want them to be shared between objects.
In this example we add two methods to our $B to get the current X and Y coordinates of the mouse cursor within the web page.We add them in a way that makes them specific to this object because in this instance our $B object provides us with a standard way to interface with the browser itself and as there is only the one browser involved in any given display of the web page we will never need to create multiple objects of this type.
$B = {
sWidth: screen.availWidth,
sHeight: screen.availHeight,
width: window.innerWidth || document.documentElement.clientWidth || document.body.clientWidth,
height: window.innerHeight || document.documentElement.clientHeight || document.body.clientHeight,
left: (window.pageXOffset>-1) ? window.pageXOffset : document.documentElement.scrollLeft || document.body.scrollLeft,
top:(window.pageyOffset>-1) ? window.pageyOffset : document.documentElement.scrollTop || document.body.scrollTop,
mouseX: function(evt) {var evt = window.event || evt; return evt.clientX ? evt.clientX + this.left : evt.pageX},
mouseY: function(evt) {var evt = window.event || evt; return evt.clientY ? evt.clientY + this.top: evt.pageX}
};