Web Developer's Virtual Library: Encyclopedia of Web Design Tutorials, Articles and Discussions
 Discussion Forums
 HTML, XML, JavaScript...
 Software Reviews
 Editors,Others...
 Top100
 JavaScript Tutorials, ...
 Tutorials
 ASP, CSS, Databases...
 Discussion List
 FAQ, Roundup, Configure ...
 Authoring
 HTML, JavaScript, CSS...
 Design
 Layout, Navigation,...
 Graphics
 Tools, Colors, Images...
 Software
 Browsers, Editors, XML...
 Internet
 Domains, E-Commerce, ...
 WDVL Resources
  Intermdiate, Tutorials,...
 WDVL
 Discussion Lists, Top 100,...
 Technology Jobs


WDVL Newsletter

Active Server Pages
JSP/Java Servlets
Microsoft SQL Server
Daily Backup
Dedicated Servers
Streaming Audio/Video
24-hour Support    

jobs.webdeveloper.com

Hiermenus


e-commerce
Partner With Us















Developer Channel
FlashKit.com
JavaScript.com
JavaScriptSource
Developer Jobs
ScriptSearch
StreamingMediaWorld
Web Developer's Journal
Web Developer's Virtual Library
WebDeveloper.com
Webreference
Web Hosts
XMLfiles.com

internet.com
IT
Developer
Internet News
Small Business
Personal Technology
International

Search internet.com
Advertise
Corporate Info
Newsletters
Tech Jobs
E-mail Offers


Top 10 Articles
  1. Web Developer's Virtual Library: Encyclopedia of Web Design Tutorials, Articles and Discussions
  2. JavaScript Tutorial for Programmers
  3. Design
  4. JavaScript Tutorial for Programmers - Objects
  5. JavaScript Tutorial for Programmers - JavaScript Grammar
  6. JavaScript Tutorial for Programmers - Versions of JavaScript
  7. Cascading Style Sheets
  8. JavaScript Tutorial for Programmers - Embedding JavaScript
  9. JavaScript Tutorial for Programmers - Functions
  10. Authoring JavaScript
Domain Name Lookup
Search to find the availability of a domain name. Just enter the complete domain name with extension (.com, .net, .edu)

Portability

March 15, 1999

While writing some modular code, you realize that you really need a module which whips up a perfect chocolate mousse -- light and airy, yet with a strong hit of chocolate cut against the tang of a coffee subflavor. Problem is, you don't really know how to make the perfect mousse -- but why re-invent the wheel? You ask around and find that someone else has already coded a module called airyMousse() and it does just what you need.

A portable module is modular, to be sure, but it goes one step further -- it operates in a world unto itself without relying on conditions or data existent in other modules within the whole program. A portable module may or may not require some incoming data to work with and it may or may not return some outgoing data at the end; but within its own machinations it keeps to itself.

A main technique in creating portable modules is to use local variables. A local variable is a value label which is only valid within the given function. It has no life outside the function and does not interfere with any variables of the same name outside the function. In JavaScript you use the var statement to declare a local variable within a function, or you create local variables with incoming data in the function definition.

function airyMousse
 (eggs,sugar,cream,coffee,chocolate)
{ var base=eggs*sugar;
  var liquids=(coffee/2)+(chocolate*3);
  var base2=base+cream;
  whip(base);
  whip(base2);
  return base+base2+liquids;
}

The function airyMousse() accepts several incoming parameters -- the data passed by the calling statement is assigned to the local variables specified in the function definition: eggs, sugar, cream, coffee, and chocolate. Within the function itself several local variables are declared for working with the data: base, base2, and liquids. Because these are local to this function these variables are unknown to any other parts of the program and do not affect any variables of the same name elsewhere. In this way, this function is portable because it could be used in virtually any program without needing to know about its other parts.

Modularity
Creating Portable and Modular Client-Side Scripts
Embedding Code


Up to => Home / Authoring / Scripting / Modular




Jupiter Online Media: internet.comearthweb.comDevx.commediabistro.comGraphics.com

Search:

Jupitermedia Corporation has two divisions: Jupiterimages and Jupiter Online Media

Jupitermedia Corporate Info


Legal Notices, Licensing, Reprints, & Permissions, Privacy Policy.

Web Hosting | Newsletters | Tech Jobs | Shopping | E-mail Offers