Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 10 of 10
  1. #1
    New Coder
    Join Date
    Jun 2007
    Posts
    12
    Thanks
    0
    Thanked 0 Times in 0 Posts

    trying to learn javascript. Not much sucess.

    Ok, very recently I've begun reading about javascript, because I would like to be able to generate some minor special effects to work under conditions where certain javascript isn't permitted. Normally I would just integrate scripts created by others(a million thanks to them), but much of it isn't permitted.

    The problem is, I can't find some decent well written information that's usable for someone who has no programming background whatsoever. I can't believe that something that utilizes logic that a child in grade school could understand and explain in plain english, could be so obscured by such convoluted, half baked, and incompetent 'teaching'.

    Is there some one than can describe the basic grammar of javscript for me?
    Last edited by bananafiend; 06-14-2007 at 05:29 AM.

  • #2
    Senior Coder CFMaBiSmAd's Avatar
    Join Date
    Oct 2006
    Location
    Denver, Colorado USA
    Posts
    3,147
    Thanks
    2
    Thanked 333 Times in 325 Posts
    This is a pretty basic introduction - http://w3schools.com/js/default.asp
    If you are learning PHP, developing PHP code, or debugging PHP code, do yourself a favor and check your web server log for errors and/or turn on full PHP error reporting in php.ini or in a .htaccess file to get PHP to help you.

  • #3
    New Coder
    Join Date
    Jun 2007
    Posts
    12
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Okay I have a specific questions, there are a few things that I find are never explained.

    Do periods always and only separate objects and methods?

    what exactly is the role of curly brackets "{}"?

    What exactly are arguments? Where can they go, what do they apply to? Does it work like object.method(argument)?

    What exactly is the role of the two rounded brackets "()"? What can they contain what can't they etc, etc?

    For example, this confuses me:

    document.write(txt.toUpperCase())

    Document is the object, write is a method...or a property? If it's not a property what is a property? Regardless of which it is, is it always followed by the rounded brackets as seen after toUpperCase? If write is a method, is txt a property of write? Does that mean properties only follow methods?

    txt.toUpperCase just looks like another object and method, but is it? if it isn't how the heck am I supposed to tell the difference?...nobody explains this!

    Gah, in this one line there is so much unexplained, but the tutorial just moves on like I'm supposed to know it. As usual the basic building blocks arent clearly defined before they start slapping things together.

  • #4
    New Coder
    Join Date
    May 2007
    Posts
    25
    Thanks
    0
    Thanked 0 Times in 0 Posts
    1. Periods can either separate objects from methods or be a character in a string.
    Some languages use them for string concatenation, but not javascript.

    2. Curly brackets (braces) separate "blocks" of code which logically fit together. For instance, a looping construct might look like this
    Code:
    while(x)
    {
       y
    }
    Where the braces "clump together" all the actions which need to be looped.

    3. Arguments are anything passed to a method or a function. Like this
    Code:
    object.method(argument);
    or
    Code:
    function(argument);
    All methods and functions have signatures which tell you what sort of arguments need to be passed in for the method to work properly which will look like - function(int i, int j);
    That's just an example though, it's not always 2 integers.

    4. Round brackets (parenthesis) have 2 purposes depending on the context. They can either contain the arguments being passed into a function/method, or they change the precedence order of operators (just like in math).
    Like the statement x = 5 * 3 - 7 would result in 8 but x = 5 * (3 - 7) would result in -20.
    This is also useful when dealing with a combination of floating point and integer operations.

    5. document.write(txt.toUpperCase()); is writing a string to the screen. Presumably txt is a variable which contains a string. The function toUpperCase() is being executed on the string txt. Then the whole thing is being passed to the function document.write(); (and yes, document is the object being acted on and write is the method). Unless you see binary operators hanging around (+,-,*,/,% a few more) parenthesis can almost always be assumed to contain the arguments to a method/function.
    txt is indeed another object - it's a string object. Just think of object like special large beefy primitive variables (although they are not by any means).
    An integer might contain the number 7, but an object might contain the number 7 and the number 8.5 and some operations (methods) to manipulate those numbers.

    6. I would suggest looking up on the basics of programing before becoming frustrated with the intricacies of a specific language. Once you understand what programming is really all about, the rest is just syntax.
    Last edited by Rubby; 06-14-2007 at 07:29 AM. Reason: typo

  • #5
    New Coder
    Join Date
    Jun 2007
    Posts
    12
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I wish the authors of most tutorials were as explicit as you were, though I could still drown you in a million questions.

    So the parenthesis indicate the order hierarchy of what is completed before it's passed onto the next stage and it goes from left to right?

    So basically you have the structure "object.method(argument)" that can be repeated infinitely within itself as each argument is actually just another object.method set that is performed before it's passed on to the object.method to it's left?

    it's basically

    object.method<--(object.method<--(object.method<--(object.method))

    and so on?

    When does the content contained in braces come in then, or am i way off?

    If it's required that I make this a full fledged programming education just to pick up some javascript, I'm not sure that it's worth it, but i'll look around for some general programming stuff.

  • #6
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    18,303
    Thanks
    203
    Thanked 2,562 Times in 2,540 Posts
    Try and get hold of a book called "JavaScript in Easy Steps" by Mike McGrath.
    Published Computer Step www.ineasysteps.com.
    It is an excellent beginner's instruction book, and I am sure will answer all your questions. (Third Edition April 2006 is £10.99 - but available from Amazon and bookshops across the world).

  • #7
    New Coder
    Join Date
    May 2007
    Posts
    25
    Thanks
    0
    Thanked 0 Times in 0 Posts
    It's not actually infinite many object.method(object.method(object.method)));
    Remember, an object is just another variable. You could just as easily say document.write(7); as document.write(txt.toUpperCase()); It all depends on what you want to do and on what is in the function signature. You could also say something like document.write(txt); which would write the text to screen without making it upper case first.

  • #8
    Master Coder felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, Australia
    Posts
    6,642
    Thanks
    0
    Thanked 649 Times in 639 Posts
    Also you need to remember that document.write() is deprecated and should not be used at all. If you want to update the web page you should use the appropriate DOM commands or innerHTML.
    Stephen
    Learn Modern JavaScript - http://javascriptexample.net/
    Helping others to solve their computer problem at http://www.felgall.com/

    Don't forget to start your JavaScript code with "use strict"; which makes it easier to find errors in your code.

  • #9
    New Coder
    Join Date
    Jun 2007
    Posts
    12
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I'll check out that book.

    So, an object is either a variable predefined by the language designers and held in an a 'dictionary' within the browser for reference, or a variable defined by you which is referenced within the document, and methods are actions that can be taken on that objects properties, so properties have to be predefined also?

    How do you define properties then...? How do you define methods or are methods only definable by the language designers...?

    The foundation structure is essentially Object.method(argument) and the argument structure can simply be (object), in which case it ends and is passed on to the left, or continued by following with a method that influences that objects predefined properties?

    I've got a feeling I'm wandering further off the path with every step.

    Last edited by bananafiend; 06-14-2007 at 09:21 PM.

  • #10
    Master Coder felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, Australia
    Posts
    6,642
    Thanks
    0
    Thanked 649 Times in 639 Posts
    object.method()
    object.property <-- note no ()
    Stephen
    Learn Modern JavaScript - http://javascriptexample.net/
    Helping others to solve their computer problem at http://www.felgall.com/

    Don't forget to start your JavaScript code with "use strict"; which makes it easier to find errors in your code.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •