objects and web scripting
scripting typically involves creating objects in order to execute certain tasks to achieve a desired outcome. and so … how do i create an object? it sounds silly, really. but, honest … its abstract … a tough concept around which to wrap one’s head. its the core of modern-day programming, though. so i had better start getting it.
object creation involves 2 steps.
(1). create an object definition ~ the code containing methods and properties of the object. methods ~ directions for making the object. properties ~ characteristics that typify the object.
create a constructor function ~ a named group of 1 or more programming statements that can create new objects. note – by convention, capitalize the first letter of a constructor function.
add properties ~ identified by object name “dot” property name. refer to the newly created, not yet instantiated objects as “this”
objectName.propertyName = value
add methods ~ (methods = functions called from within the method.) name the method, assign a function. use action words when naming methods. identified using the syntax below. (argument = input to subroutine … used to assign a value to a property of the new object)
objectName.methodName(arguement)
(2) instantiation ~ create an instance of the newly defined object. specify a unique name for the new object. assign the object to the recently created object definition using the “new” keyword.
steps in object instantion ~ variable assigned a value ~ variable value passed as a parameter (parameters act as local copies of the argument) to the new object ~ parameter used to assign variable value to an object property ~ object property used by the object’s show method ~ show calls the object’s display method, which writs to the browser.
No comments yet
Leave a reply








