Supplementary

findIn, a JavaScript Function that Locates Objects within other Objects

Object structures in programming can be large and complex, which can make locating a given member of a given object awkward and inefficient. JavaScript is no exception, and this section presents a function called findIn that locates a member or members of an object, and members of those sub-objects, given a reference to a root object and, optionally, a set of search criteria.

findIn also accepts a reference to a call-back function, which it invokes whenever it locates an object-member that satisfies a given search criterion, and this feature allows the technology to be used in conjunction with AspectJS. This yields the ability to intercept calls to far-flung methods simply, en masse and using regular-expression syntax.

As with the AspectJS AJS-object, and all other libraries available from this site, findIn does not check the type, number and value of parameters passed by their callers. Instead, an optional adjunct is provided called findIn_DbC ('findIn Design by Contract'), which uses the AJS object to fulfill that role.

Only one call to findIn_DbC is required, and all code that calls findIn remains unchanged and continues to operate normally. Argument-checking can therefore be enabled and disabled trivially, thus giving equally trivial control over the overheads it incurs. Programmers can thereby enjoy all of the benefits of a design-by-contract approach during development, yet avoid all of its costs when the system is deployed.