Archive for the ‘web programming’ Category
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.
a primer on scripting objects
client-side scripting ~ runs in a browser: interpreted when browser loads page. to create ~ must specify type/language attribute in opening script tag. the document object methods document.write ( ) and document.writeln ( ) return output to the web page. document.writeln inserts a carriage return at the end of each line. to call external client-side script files ~ use *.js format/file extension to denote the file with the script tag’s source (src) attribute. when creating an external script file, just begin writing your script ~ no special tags required.
<script> src=’filenamehere.js’ type = ‘text/JavaScript’… </script>
server-side scripting (windows/MS) ~ runs on a web server: interepreted by the web server’s script engine. to create ~ can use (i) script tag pair with script’s runat attribute set to server, or (ii) inline tags.
(i) <script> type = ‘text/JavaScript’ runat=’server’… </script>
(ii) <% … %>
the asp (active server page) model comprises 6 objects: response, request, application, session, server, objectContext. to return output to the web page, use the response object’s write method: response.write( ). to reference an external server-script, call the *.inc file. all server-side code gets stripped from the html code before browser/client receives it ~ cannot be viewed via view source code.
Leave a Comment
Leave a Comment







