Oh, ok I'm going to read over this thread up to this point a few times :)

As a whole objects are becoming clearer. I want to go a question I had posted :-)

function jar (chair,food,fastlaptop) { 
 this.chair = chair; //1
 this.food = food; //2
 this.laptop = fastlaptop; //3
 }
var one = new jar ("wooden","bread","dell");
var apple = jar.laptop;
document.write("I something " +two+ " something");

Not creating the extra variable works like a charm, thanks for that tip :-).

I'd like to know why when I create the extra variable does the write command not work as I've placed the object jar.laptop in the second variable ?

Use jsfiddle.net or jsbin.com to test it out. But you will find that you made a few mistakes there.

1. Don't put spaces between the function name and the braces jar (...)->jar(...), might not give you an error, but I've never seen it done anywhere. And on a text wrap you'll want those close to each other for readability

2. Take a better look at the code:

var one = new jar ("wooden","bread","dell");
var apple = jar.laptop;

Should be the following (2 corrections there. var is only used once, and the apple's assignment value changed)

var one = new jar("wooden", "bread", "dell"),
    apple = one.laptop;

3.

document.write("I something " +two+ " something");

Variable two wasn't created anywhere, so nothing will get written.

Imagine you need lots of jar objects:

function jar (chair,food,fastlaptop) { 
    this.chair = chair; //1
    this.food = food; //2
    this.laptop = fastlaptop; //3
}

var obj_a = new jar("w", "b", "d"),
    obj_b = new jar("wo", "br", "de"),
    obj_c = new jar("woo", "bre", "del"),
    obj_d = new jar("wood", "brea", "dell"),
    obj_e = new jar("wooden", "bread", "della");

 console.log("Object A's chair is: " + obj_a.chair);
 console.log("Object B's chair is: " + obj_b.chair);
 console.log("Object C's chair is: " + obj_c.chair);
 console.log("Object D's chair is: " + obj_d.chair);
 console.log("Object E's chair is: " + obj_e.chair);

The output is:

"Object A's chair is: w"
"Object B's chair is: wo"
"Object C's chair is: woo"
"Object D's chair is: wood"
"Object E's chair is: wooden"

Check the JS BIN and use it to mess around and read the errors it shows.

First of all, my dumb mistake, sorry !
Second, with your help it's becoming clearer and clearer :)

Is there any difference if I change what the object means as in this case ? I hope the code clears any confusion to what I mean ? :)

function jar (chair,food,fastlaptop) {
this.chair = chair; //1
this.food = foody; //2
this.laptop = fastlaptop; //3
}
function jar(a, b, c, d, e, f) { 
    this.a = d;
    this.b = e;
    this.c = f;
}
var test = new jar("one", "two", "three", "four", "five", "six");

Try this one out... see what happens

function jar(a, b, c, d, e, f) {
this.a = d;
this.b = e;
this.c = f;
}
var test = new jar("one", "two", "three", "four", "five", "six");

document.write("I something " +test.c+ " something"); // Writes out "six". You have six parameters but only three objects so therefore if I'm correct there are only three objects I can use ?

    function jar(a, b, c, d, e, f) {
    this.a = d;
    this.b = e;
    this.c = f;
    }
    var test = new jar("one", "two", "three", "four", "five", "six");
var res = jar.b;
write("I something " +res+ " something");

If I include the function, isn't the above block of code correct, or is there a syntax error ?

var res = test.b; //NOT jar.b

You don't have 3 objects. You have:
- one object called test
- of type jar with
- 3 properties this.a, this.b and this.c and
- six parameters passed through the constructor a, b, c, d, e, f.

The variable that contains the instance is the object !

The following code works, sometimes it can be syntax errors other times I find JSFiddle to sometimes not work as expected, then sometimes I find JSBin doesn't always work either. I then rule out that the block of code is wrong, sometimes it's no wrong and I have to test again, or somtimes I need to take a walk :)

function jar(a, b, c, d, e, f) {
this.a = d;
this.b = e;
this.c = f;
}
var test = new jar("one", "two", "three", "four", "five", "six");
var res = test.a;
document.write("I something " +res+ " something");

It contains an instance of the object, therefore it is the object.

var test = new jar("one", "two", "three", "four", "five", "six");
document.write("I something " + test.a + " something");

You don't need to create the variable res just call the object's property directly, it makes the code more readable when you have several objects.

Off-topic
I know what you mean, sometimes a walk is the best coding solution xD But my colegue keeps telling me the computer/software is never wrong... it's always the user... sometimes I wanna throw things at him, but he's right lol

Bypassing the extra variable is what I will do, I wanted to get the block of code to work with the extra variable.

The computer only knows how to crunch numbers, He is right,most of the time it is user fault, remember one thing, a human did program the language for the computer. You could throw something at him, he isn't 100% right, tell him he's 98% right !

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.