• ARCHIVES 
  • » Oh well, i made this topic because i've seen alot of codes here being misused. So what is a function? functions is a block of code that perform a routine or process. it can return a value or not ret

Pages: 12344

Oh well, i made this topic because i've seen alot of codes here being misused. So what is a function? functions is a block of code that perform a routine or process. it can return a value or not ret

marfillaster
» FTalkAddict
FTalk Level: zero
300
0
1969-12-31

Oh well, i made this topic because i've seen alot of codes here being misused. So what is a function? functions is a block of code that perform a routine or process. it can return a value or not ret

Oh well, i made this topic because i've seen alot of codes here being misused. So what is a function? functions is a block of code that perform a routine or process. it can return a value or not return anything at all, just execute a block of code. It can also accept arguments or parameters. [b]A function must not be duplicated[/b] in a document(which may contain more that 1 javascript). However it can be called many times. Here's some example of the syntax, foo can be anything provided it doesnt begin with number and only contains letter and underscore. [b]function that execute a code[/b] [quote]function foo() { alert("hi"); }[/quote] how to call: [quote]foo();[/quote] will show an alert with "hi" message [b]function that execute a code but requires a parameter[/b] [quote]function foo(message) { alert(message); }[/quote] how to call: [quote]foo("hi");[/quote] will show an alert with "hi" message [b]function returns a value[/b] [quote]function foo() { return "hi"; }[/quote] how to call: [quote]alert(foo());[/quote] will show an alert with "hi" message [b]function returns a value but requires a parameter[/b] [quote]function foo(message) { if(message) return true; return false; }[/quote] how to call: [quote]alert(foo("hi"));[/quote] will show an alert with "true" message so now you know how to use a function. [b]As I said a function must not be duplicated[/b], it will cause bugs if you do. Why use functions? Basically we want our code short, in practicality we use function so that we can execute the same code many times without making the same code. What tricks here in ftalk do use functions? All of my codes uses function. That includes addSideBar, addMainbar and wvm. Ok here's an example how we will apply the purpose of a function, we will use addSideBar. Here's the addSideBar function, <">Say we want to put three sidebars in our profile, each one will have an image link. Again, we only need a single block of addSideBar function for the three sidebars. [quote]if (!attachOnLoadHandler(function(){editContent()})) parent.onload = function(){editContent()}; function editContent() { var html1="<a href=\"somelink1.html\"><img src="someimage1.bmp" /></a>"; addSideBar("Title 1",html1,"sidebar1"); var html2="<a href=\"somelink2.html\"><img src="someimage2.bmp" /></a>"; addSideBar("Title 2",html2,"sidebar2"); var html3="<a href=\"somelink3.html\"><img src="someimage3.bmp" /></a>"; addSideBar("Title 3",html3,"sidebar3"); } function addSideBar(head,htm,div_id) { var innerHtm=htm; var cont= "<div id='"+div_id+"' class='commonbox "+div_id+"'>"+ "<h2>"+head+"</h2>"+ "<div id='content_"+div_id+"'>"+ innerHtm+ "</div>"+ "</div>"; try { var obj=document.createElement("<li>"); } catch(e) { var obj=document.createElement("li"); } var x=document.getElementById("friends_2_2"); x.parentNode.parentNode.appendChild(obj); obj.innerHTML=cont; }[/quote] wait a minute, where the hell did that attachOnLoadHandler come from? attachOnLoadHandler is also a function, one of friendster's js(http://images.friendster.com/200706A/js/friendster_v1.js) already does have this function so we do no longer need to copy the whole attachOnloadhandler code. in the code above, we only called it and passed a parameter which is also a function(editcontent). So this demonstrates why functions must not be duplicated. I hope you get my point...

Last edited by Ephemeral (2008-03-04 08:36:27)

eykalsyamim
» FTalkManiac
FTalk Level: zero
842
0
1969-12-31

Re: Oh well, i made this topic because i've seen alot of codes here being misused. So what is a function? functions is a block of code that perform a routine or process. it can return a value or not ret

this is gud..lecture time.. :thumbsup: :thumbsup: newbie must undstnd this 1st.. :thumbsup:

Last edited by eykalsyamim (2007-06-14 04:58:59)

feruzz
» Banned
FTalk Level: zero
1557
0
1969-12-31

Re: Oh well, i made this topic because i've seen alot of codes here being misused. So what is a function? functions is a block of code that perform a routine or process. it can return a value or not ret

yeah..I've learn something new... =) :thumbsup: :thumbsup:
marfillaster
» FTalkAddict
FTalk Level: zero
300
0
1969-12-31

Re: Oh well, i made this topic because i've seen alot of codes here being misused. So what is a function? functions is a block of code that perform a routine or process. it can return a value or not ret

i hope this will help all of you guys
feruzz
» Banned
FTalk Level: zero
1557
0
1969-12-31

Re: Oh well, i made this topic because i've seen alot of codes here being misused. So what is a function? functions is a block of code that perform a routine or process. it can return a value or not ret

yeah...many newbies didn't understand a [b]function[/b]...they just copied & paste :wasted: so I hope this tutorial would help them =) keep it up Ken :thumbsup:
eykalsyamim
» FTalkManiac
FTalk Level: zero
842
0
1969-12-31

Re: Oh well, i made this topic because i've seen alot of codes here being misused. So what is a function? functions is a block of code that perform a routine or process. it can return a value or not ret

yup..like me..i'm juz a newbie..didnt know anythg..juz copy and paste.hehe.. gud job.. :thumbsup: :thumbsup:
feruzz
» Banned
FTalk Level: zero
1557
0
1969-12-31

Re: Oh well, i made this topic because i've seen alot of codes here being misused. So what is a function? functions is a block of code that perform a routine or process. it can return a value or not ret

[quote=eykalsyamim]yup..like me..i'm juz a newbie..didnt know anythg..juz copy and paste.hehe.. gud job.. :thumbsup: :thumbsup:[/quote] like you?? :o :o :o :o
leftalone
» FTalkAddict
FTalk Level: zero
449
0
1969-12-31

Re: Oh well, i made this topic because i've seen alot of codes here being misused. So what is a function? functions is a block of code that perform a routine or process. it can return a value or not ret

haha tanks for sharing sir ken :)
axce.lan
» n00b
FTalk Level: zero
4
0
1969-12-31

Re: Oh well, i made this topic because i've seen alot of codes here being misused. So what is a function? functions is a block of code that perform a routine or process. it can return a value or not ret

nice info...even myself dunno how it works... :lol: :P
- razian -
» FTalker
FTalk Level: zero
156
0
1969-12-31

Re: Oh well, i made this topic because i've seen alot of codes here being misused. So what is a function? functions is a block of code that perform a routine or process. it can return a value or not ret

thanks for info thanks 4 sharing too :D
ric25
» FTalkAddict
FTalk Level: zero
326
0
1969-12-31

Re: Oh well, i made this topic because i've seen alot of codes here being misused. So what is a function? functions is a block of code that perform a routine or process. it can return a value or not ret

thanks for the info.. ;) :thumbsup:
jagcopra
» FTalker
FTalk Level: zero
175
0
1969-12-31

Re: Oh well, i made this topic because i've seen alot of codes here being misused. So what is a function? functions is a block of code that perform a routine or process. it can return a value or not ret

hehe.. thx for the tutorial.. simple yet very useful!!.. you can use this simple tutorial to a complicated and more great scripts!!.. =)
TA Juleigtin Siahaan
» FTalkAgent
FTalk Level: zero
2150
0
1969-12-31

Re: Oh well, i made this topic because i've seen alot of codes here being misused. So what is a function? functions is a block of code that perform a routine or process. it can return a value or not ret

wew.. :D :D Waahhh..Finally you posted this topic.. :thumbsup: :thumbsup: I think this topic will be useful.. =) =) Thanks 4 sharing it Mr.Marfillaster.. :eh: :)
xavierkym
» FTalkFreak
FTalk Level: zero
1651
0
1969-12-31

Re: Oh well, i made this topic because i've seen alot of codes here being misused. So what is a function? functions is a block of code that perform a routine or process. it can return a value or not ret

wow... a great help 4 everyone.. weeeee... :D
joe1084
» n00b
FTalk Level: zero
26
0
1969-12-31

Re: Oh well, i made this topic because i've seen alot of codes here being misused. So what is a function? functions is a block of code that perform a routine or process. it can return a value or not ret

i got headache :wallbash:
marfillaster
» FTalkAddict
FTalk Level: zero
300
0
1969-12-31

Re: Oh well, i made this topic because i've seen alot of codes here being misused. So what is a function? functions is a block of code that perform a routine or process. it can return a value or not ret

why?
cip6192
» FTalkAddict
FTalk Level: zero
377
0
1969-12-31

Re: Oh well, i made this topic because i've seen alot of codes here being misused. So what is a function? functions is a block of code that perform a routine or process. it can return a value or not ret

wow marfilla thanks for sharing that haha i already knew that but it did a lot of helps for those who asking how to put mp3's, videos, cbox, WVM etc. they can really do it in one js file only right? :D comment me if im wrong :P
marfillaster
» FTalkAddict
FTalk Level: zero
300
0
1969-12-31

Re: Oh well, i made this topic because i've seen alot of codes here being misused. So what is a function? functions is a block of code that perform a routine or process. it can return a value or not ret

yeah, only one file, and much smaller...
joez
» FTalker
FTalk Level: zero
128
0
1969-12-31

Re: Oh well, i made this topic because i've seen alot of codes here being misused. So what is a function? functions is a block of code that perform a routine or process. it can return a value or not ret

it grinds my brain.... =D =D
diabolicious
» FTalkManiac
FTalk Level: zero
721
0
1969-12-31

Re: Oh well, i made this topic because i've seen alot of codes here being misused. So what is a function? functions is a block of code that perform a routine or process. it can return a value or not ret

:o now i understand it a bit <~~~ err im still cursed :crybaby:
  • ARCHIVES 
  • » Oh well, i made this topic because i've seen alot of codes here being misused. So what is a function? functions is a block of code that perform a routine or process. it can return a value or not ret

Pages: 12344

Board footer

© 2024 F Talk

Current time is 21:20

[ 10 queries - 0.034 second ]
Privacy Policy