JSWindows (a JavaScript Inheritance Demo) Library Functions

© 2013, Martin Rinehart

JSWindows (a JavaScript Inheritance Demo) uses its own library functions, no others.

The a2s() Function

console.log( jsw.a2s(array) );

Utility, converts array to string (used for debugging code).

The delete_delem() Function

jsw.delete_delem( delem );

Recursively deletes all DOM objects within a delem and then deletes the delem. (Suspenders and belt coding because one browser supplier doesn't correctly garbage collect DOM elements.)

The draw_border() Function

jsw.draw_border( canvas, left,top, width,height, bwidth, color );

Draws a rectangle's border within canvas. (Any DOM element may be used as a canvas.) The size specs are CSS-style: they are the dimensions of the hole in the doughnut.

The draw_rect() Function

jsw.draw_rect(draw_border( canvas, left,top, width,height, bwidth, color );

Draws a rectangle within canvas. (Any DOM element may be used as a canvas.)

The implement() Function

jsw.implement( object, capability );

Adds the capability's (interface's) methods to the wobj's prototype and adds properties to the wobj as required by the capability (interface). The capability must provide a class method Capability.add() that implements itself. This add() method is not part of the capability added to the wobj.

The o2s() Function

console.log( jsw.o2s(any_object) );

This is a utility function that converts any object into a string for use during development.

the recolor_children() Function

jsw.recolor_children( dom_element, color );

Changes the background color and border color of the children of the dom_element to the specified color. (Colors children, but not grandchildren.)

The sum() Function

var sum_object = jsw.sum( base_object, added_object );

Creates a new object by copying the base_object and then "adding" the properties of the added_object. "Adding" means either adding new properties, or replacing existing properties.

All properties of the base_object are copied into the new object. The names are duplicated and shallow copies are made of the values. The property names of the added_object are added to the new object, if they do not already exist. The values are copied (shallow) from the added_object. This will replace the values that came from the base_object if there are duplicate names.

Return: the new (sum) object.

Side effects: none. (The argument objects are unchanged.)

"has_own" checking: none. Properties in the prototype chains of the base and added objects become properties of the sum object.

The window_size() Function

var wid_hgt = jsw.window_size();
// use wid_hgt.width and/or wid_hgt.height

Returns a two-property object:

var obj = {
    width: the window's width, in pixels,
    height: the window's height, in pixels

The "window" is the client area of the browser. (This is the writable area in many smaller devices, the area provided by the user on larger devices.)

The comment in the code says that this function "guesses" the window size. If you can do better, please contact the author!

Feedback: MartinRinehart at gmail dot com

# # #