The Cellar  

Go Back   The Cellar > Main > Technology
FAQ Community Calendar Today's Posts Search

Technology Computing, programming, science, electronics, telecommunications, etc.

Reply
 
Thread Tools Display Modes
Old 03-23-2004, 04:25 PM   #16
hot_pastrami
I am meaty
 
Join Date: Dec 2001
Location: Salt Lake City, UT
Posts: 1,119
So now you should have an idea what a variable is, and what a function is. A variable is a piece of data, and a function is code that you can pass arguments to in order to execute one or more actions. So that leads us to:

OBJECTS

Let's say you wanted to write a program that simulates a car. You might define a few variables to set the parameters of the car, like so:
Code:
var make = "Chevrolet";
var model = "Camaro SS";
var exteriorColor = "black";
var interiorColor = "charcoal";
var horsePower = "410";
...and you might create functions for your car, like start(), accelerate(), brake(), etc (I'll get into how to create your own functions shortly).

Well, that's all fine and dandy, but what if you wanted your program to simulate two cars? Do you add the car name to the variables, and define an entirely separate set for the new car? Perhaps. But what if you want to simulate 100 cars? That would be a lot of variable naming. This is one useful application of programming Objects.

An object is a variable which has it's own sub-set of variables and functions. I can define an object called Car, which contains all of the above variables and methods. Then, every instance of Car I create has it's own unique values for those variables, and when I run a function for one of the Car objects, the other Car objects are unaffected.

A bit later we'll get into how to create custom objects, but Javascript does automatically create a bunch of objects automatically, such as the document object, which is created to allow you access to the webpage you're working with.

To access an object's variables and functions, you provide the object variable, and then a period, and then the variable name of function name that you want. For example, with our fictional Car object:
Code:
camaroSS.accelerate();
mustangGT.accelerate();
alert("Who's your daddy?");
...or, for something that uses a built-in object:
Code:
document.write("Some text");
...this will print the words Some text to the browser window. Javascript also creates an object called window to provide access to the browser window. You can use the alert() function we went over previously to display the contents of the window object's location variable, which contains the current URL:
Code:
alert(window.location);
Don't worry if you don't understand it fully, objects can sort of be learn-as-you-go.

More later.
__________________
Hot Pastrami!
hot_pastrami is offline   Reply With Quote
Old 03-23-2004, 10:43 PM   #17
lumberjim
I can hear my ears
 
Join Date: Oct 2003
Posts: 25,571
I'm right with you. I have to read each line of your description 3 times, but it makes sense if I read slowly. I have a question, though. The very first characters of each code....are those commas, or periods?



it seems like they don;t matter. I did this without, and it works:

this will be funnier for you if you don;t read the code first, but just paste it into the tester and run it.......but it still won;t be all that funny, so don;t get all excited



var prompt = "Click OK if you understand this shit.\nClick Cancel if it's making your hair hurt.";

if (confirm(prompt)) {
document.write("yeah, bullshit, fonzie");
}
else {
alert("You're pretty dumb.");
document.write("yup, pretty dumb");
}
__________________
This body holding me reminds me of my own mortality
Embrace this moment, remember
We are eternal, all this pain is an illusion ~MJKeenan
lumberjim is offline   Reply With Quote
Old 03-23-2004, 11:09 PM   #18
hot_pastrami
I am meaty
 
Join Date: Dec 2001
Location: Salt Lake City, UT
Posts: 1,119
Quote:
Originally posted by lumberjim
The very first characters of each code....are those commas, or periods?
I'm not sure what you're referring to here...
__________________
Hot Pastrami!
hot_pastrami is offline   Reply With Quote
Old 03-24-2004, 05:37 AM   #19
lumberjim
I can hear my ears
 
Join Date: Oct 2003
Posts: 25,571
Quote:
Originally posted by hot_pastrami

I'm not sure what you're referring to here...
code:
.
var make = "Chevrolet";
var model = "Camaro SS";
var exteriorColor = "black";
var interiorColor = "charcoal";
var horsePower = "410";
.


are these even part of the code, or are you just putting them there out of habit?
__________________
This body holding me reminds me of my own mortality
Embrace this moment, remember
We are eternal, all this pain is an illusion ~MJKeenan
lumberjim is offline   Reply With Quote
Old 03-24-2004, 06:33 AM   #20
Happy Monkey
I think this line's mostly filler.
 
Join Date: Jan 2003
Location: DC
Posts: 13,575
What browser are you using? On mine, those are horizontal lines - not pat of the code at all.
__________________
_________________
|...............| We live in the nick of times.
| Len 17, Wid 3 |
|_______________| [pics]
Happy Monkey is offline   Reply With Quote
Old 03-24-2004, 06:47 AM   #21
jinx
Come on, cat.
 
Join Date: Nov 2003
Location: general vicinity of Philadelphia area
Posts: 7,013
-lumberjim

netscape 7.1
__________________
Crying won't help you, praying won't do you no good.
jinx is offline   Reply With Quote
Old 03-24-2004, 06:51 AM   #22
jinx
Come on, cat.
 
Join Date: Nov 2003
Location: general vicinity of Philadelphia area
Posts: 7,013
see?
Attached Images
 
__________________
Crying won't help you, praying won't do you no good.
jinx is offline   Reply With Quote
Old 03-24-2004, 10:17 AM   #23
hot_pastrami
I am meaty
 
Join Date: Dec 2001
Location: Salt Lake City, UT
Posts: 1,119
Quote:
Originally posted by lumberjim
are these even part of the code, or are you just putting them there out of habit?
Those are supposed to be horizonatal lines, automatically added when i use the "code" vB tags. Hmm. Netscape must have issues with horizontal lines under some circustances.

What are you doing running Nutscrape anyway? What kind of daft, running-around-with-limp-wrists silly person would choose Netscape over Mozilla?
__________________
Hot Pastrami!
hot_pastrami is offline   Reply With Quote
Old 03-24-2004, 10:40 AM   #24
lumberjim
I can hear my ears
 
Join Date: Oct 2003
Posts: 25,571
I've been through this with syc and UT. I LIKE netscape. Mozilla appears to just be askin to my netscape anyway, and it does not load IM, or my tabs. I have to tell it to show me navigator tabs, and it moves slower. I'll just ignore the dots.

browser snob
__________________
This body holding me reminds me of my own mortality
Embrace this moment, remember
We are eternal, all this pain is an illusion ~MJKeenan
lumberjim is offline   Reply With Quote
Old 03-24-2004, 10:46 AM   #25
Radar
Constitutional Scholar
 
Join Date: Dec 2002
Location: Ocala, FL
Posts: 4,006
Less chatting, more programming please.
__________________
"I'm completely in favor of the separation of Church and State. My idea is that these two institutions screw us up enough on their own, so both of them together is certain death."
- George Carlin
Radar is offline   Reply With Quote
Old 03-24-2004, 10:58 AM   #26
hot_pastrami
I am meaty
 
Join Date: Dec 2001
Location: Salt Lake City, UT
Posts: 1,119
Quote:
Originally posted by lumberjim
browser snob
Man, we're just trying to help... the first step to recovery is admitting that you have a problem. So, let me take care of that right now... I admit that you have a problem. Ok, now we can move on to the second step... bitching at you about your uber-lame browser, with really smarmy quips like this:

"Netscape is the short bus of web browsers!"

"I'm not saying that anybody who uses Netscape is a dumb person, I'm just saying that even smart people are capable of doing dumb things."

"Allow me to disabuse you of the notion that your browser of choice is in any way superior to a rotting heap of rhino feces!"

I forget what the third step is, something about "intervention" or "hypertension" or "Star Trek convention." But we'll deal with that later.

Programming... right. More to come soon.
__________________
Hot Pastrami!
hot_pastrami is offline   Reply With Quote
Old 03-24-2004, 03:18 PM   #27
hot_pastrami
I am meaty
 
Join Date: Dec 2001
Location: Salt Lake City, UT
Posts: 1,119
Well, things at work just got crazy, so there problably won't be anything new today. If I have time tonight I'll post something, though.
__________________
Hot Pastrami!
hot_pastrami is offline   Reply With Quote
Old 03-24-2004, 06:06 PM   #28
lumberjim
I can hear my ears
 
Join Date: Oct 2003
Posts: 25,571
BUTTONS

hey, this is probably premature, but, how do you change the words on the buttons themselves?

does JS support that, or must you create a whole new code or object to be that prompt?

oh, and can you crack the code in a browser or OS and make it change the word that displays on the normal buttons? ie. in stead of the button saying "OK" on it, it could say " Sure, why not"
__________________
This body holding me reminds me of my own mortality
Embrace this moment, remember
We are eternal, all this pain is an illusion ~MJKeenan

Last edited by lumberjim; 03-24-2004 at 07:50 PM.
lumberjim is offline   Reply With Quote
Old 03-24-2004, 06:37 PM   #29
lumberjim
I can hear my ears
 
Join Date: Oct 2003
Posts: 25,571
{(document.bgColor = "red");
(document.write("Coolness Quotient Test Site"));
alert ("click OK to begin test");
document.write(" Results: You're a tool");
}

how do you change the colors of the words?
how do you clear the page to display the results?
how do you change the location of the text on the page?
__________________
This body holding me reminds me of my own mortality
Embrace this moment, remember
We are eternal, all this pain is an illusion ~MJKeenan
lumberjim is offline   Reply With Quote
Old 03-25-2004, 11:46 PM   #30
hot_pastrami
I am meaty
 
Join Date: Dec 2001
Location: Salt Lake City, UT
Posts: 1,119
Sorry about the delay, I'm currently being taken advantage of by my employer. I like working seven days a week for 12 hours per day.

I'll post more as soon as I am able.
__________________
Hot Pastrami!
hot_pastrami is offline   Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

All times are GMT -5. The time now is 04:16 PM.


Powered by: vBulletin Version 3.8.1
Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.