An object-oriented language allows for object-oriented programming (OOP), or writing code based on objects that interact with one another to give the end user desirable functionality within a program. Objects contain data in the form of fields (properties or variables) and code (procedures or methods).
The other two main programming methods are functional programming and procedural programming. Functional programming uses a method of coding that evaluates expressions rather than executing commands or program instructions. Procedural programming, on the other hand, is a coding paradigm that focuses on the concept of a procedure call or a set of commands that must be followed.
When using the alert command, or
alert(object), the output will typically display
[Object Object]. Thus, the content parameters of an object will not show for debugging or print (showing up on console display). However, there are ways around this in accessing an object’s content or elements within it for debugging or printing.
Most, if not all, browsers also have their own built-in debugging tools worth tapping into. For instance, Firefox has the Firefox Developer Tools that replaced Firebug, while Chrome has Chrome DevTools. Below are some general commands that should also work. For simple debugging purposes, this alert function should do in general:
In our example below, let's use
fruit as the object we want to examine since it has more variables than the apple example we used above. We can then use
toSource() method signifies a source code object fetch. Recent browsers also allow for this command to dump object content to a debugging console. You can use a DOM inspection tool as well. Below are two methods of access, with the first going to the directory and second to the debugging mode to access the content:
Besides the use of debuggers, another effective way of accessing elements of an object is to use a
foreach loop within a
printObject function that will display a text dialog box on the screen called an
alert() function, showing the object's properties and values. The
alert() function can also print an object on the screen by doing this:
alert() method below with fruit, again, as the object example in our case: