View Full Version : Syntax for passing values
07-29-2002, 09:28 PM
What is the syntax for passing values from one function to another?
07-30-2002, 08:24 AM
Syntax is always same :
function Person(sFirstName, iAge)
var objPerson = new Object();
objPerson.firstName = setFirstName(sFirstName);
objPerson.age = setAge(iAge);
if (sNamePassed == "")
var personPeter = new Person("Peter",25);
creates a new object personPeter, which has properties firstName("Peter") and age(25).
var personUnknown = new Person();
creates a new object, which has properties firstName("John") and age(0).
It doesn't matter, where functions are located, as long as you've imported them. You could encapsulate functions above, for instance functions starting with set could be included and imported in setFunctions.js etc.
07-30-2002, 11:18 AM
Originally posted by Zvona
It doesn't matter, where functions are located, as long as you've imported them.
I think I know what you meant, but I believe this is a little bit misleading: When you call a function, then it has to be defined previously to that point in your code.
So if you have a lot of code in a <script> element located in your <head>, and that code makes use of a function located in an external script called functions.js, and that file gets imported in a <script> element within you <body> element, you will receive errors.
07-30-2002, 03:03 PM
Thanks a lot for the info and example Zvona they really helped.
Powered by vBulletin® Version 4.2.2 Copyright © 2016 vBulletin Solutions, Inc. All rights reserved.