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.
Page 1 of 3 123 LastLast
Results 1 to 15 of 36
  1. #1
    New Coder
    Join Date
    Jan 2013
    Location
    Florida
    Posts
    75
    Thanks
    2
    Thanked 0 Times in 0 Posts

    a little help with Object nomenclature please

    below is some javascript that is part of a larger function that works, but that i don't understand very well. I have been watching the crockford videos, and asking some questions in this forum, and have decided that i had better understand the basic syntax or terms before i can hope to comprehend it.

    to the right of the code i have put in comments what i think is happening, and what i think the different parts are called (Object, key, property, value).

    would someone take a look and see if i have this much right ?

    thanks


    Code:
    $(document).ready(function(){      //starts the function
    
    
    
          var manifest = {                    //sets up the array-like Object "manifest"
    
          a:                                          //sets the Object "manifest" key to "a"
    		{                                  //begin property list for "a"
            filename:"01.jpg",            //adds property 'filename' with value '01.jpg' to key "a"
    		aphorism: "old",               //adds property 'aphorism' with value 'old' to key "a"
            dog:"spot"                       //adds property 'dog' with value 'spot' to key "a"
    		}                                //end property list for "a"
          } 
            
           $.each(manifest, function (){   
            alert("LL");
            });   
            
      });                                            //ends function

  • #2
    New Coder
    Join Date
    Aug 2013
    Posts
    50
    Thanks
    0
    Thanked 11 Times in 11 Posts
    Ah, I love Doug. Yeah looks like you got everything pretty correct. Feel free to PM me on Skype if you wish (thetenfold). I know quite a bit, except some stuff like creating image maps and canvas (which I suppose is technically html5). I'm not the best at explaining things but I'll try.

    I'd suggest reading several articles on whatever you're unsure about. I'd also suggest having a test.html where you can try out everything you've read about; that really sinks in information in.

  • #3
    New Coder
    Join Date
    Aug 2013
    Posts
    50
    Thanks
    0
    Thanked 11 Times in 11 Posts
    Sorry for the double post but there's no edit button.

    [hr]

    I don't suggest using jQuery until you fully understand what JavaScript is and how to use it. I see a lot of people go down the wrong path and start confusing themselves with that.

  • #4
    Master Coder felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, Australia
    Posts
    6,639
    Thanks
    0
    Thanked 649 Times in 639 Posts
    Quote Originally Posted by joesimmons View Post
    I don't suggest using jQuery until you fully understand what JavaScript is and how to use it. I see a lot of people go down the wrong path and start confusing themselves with that.
    I agree. I've seen lots of code where the person uses 20 lines of jQuery calls to do what could be done in 5 Javascript statements without jQuery. You need a bit more than beginner level JavaScript before trying to use jQuery if you want to use it properly.
    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.

  • #5
    New Coder
    Join Date
    Jan 2013
    Location
    Florida
    Posts
    75
    Thanks
    2
    Thanked 0 Times in 0 Posts
    ok. but i am puzzled by that reply. let me re-post the code :

    Code:
    (function(){      //starts the function
    
    
    
          var manifest = {                    //sets up the array-like Object "manifest"
    
          a:                                          //sets the Object "manifest" key to "a"
    		{                                  //begin property list for "a"
            filename:"01.jpg",            //adds property 'filename' with value '01.jpg' to key "a"
    		aphorism: "old",               //adds property 'aphorism' with value 'old' to key "a"
            dog:"spot"                       //adds property 'dog' with value 'spot' to key "a"
    		}                                //end property list for "a"
          } 
            
            
            
      });                                            //ends function
    no more jQuery. do my comments accurately describe what the parts are called ?

  • #6
    Senior Coder jmrker's Avatar
    Join Date
    Aug 2006
    Location
    FL
    Posts
    3,083
    Thanks
    38
    Thanked 498 Times in 492 Posts

    Question

    Your comments seem clear enough to me, but not having viewed the lessons in question,
    my attempt to use the information results in an error message indicating that the function is not found.

    Code:
    <!DOCTYPE HTML>
    <html>
    <head>
    <title> Untitled </title>
    <meta charset="utf-8">
    
    </head>
    <body>
    
    <script type="text/javascript">
    
    (function(){               // starts the function
      var manifest = {         // sets up the array-like Object "manifest"
      a:                       // sets the Object "manifest" key to "a"
        {                      // begin property list for "a"
          filename:"01.jpg",   // adds property 'filename' with value '01.jpg' to key "a"
          aphorism: "old",     // adds property 'aphorism' with value 'old' to key "a"
          dog:"spot"           // adds property 'dog' with value 'spot' to key "a"
        }                      // end property list for "a"
      }
    });
    
    // test of above
    onload = function() {
      var str = manifest.a.filename+'\n';
          str += manifest.a.aphorism+'\n';
          str += manifest.a.dog;
      alert(str);
    } 
    
    </script>
    
    </body>
    </html>

  • #7
    New Coder
    Join Date
    Jan 2013
    Location
    Florida
    Posts
    75
    Thanks
    2
    Thanked 0 Times in 0 Posts
    what lessons ? i am not a student asking for help with his homework, i'm just an aging dumbbell trying to understand javascript.

    i'm glad that my comments seem clear, but are they right ?

    thanks

  • #8
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,438
    Thanks
    75
    Thanked 4,372 Times in 4,337 Posts
    The only part I might take (minor) issue with is
    var manifest = { //sets up the array-like Object "manifest"
    Why are the contents of "manifest" any more "array-like" than (for example) the contents of "a" or "aphorism" in your example?

    After all, we could have written:
    Code:
        var foo = {
            manifest : { ... etc. ... }
        }
    And so on for as many levels as we wanted.

    The contents of "manifest" are an object, pure and simple.
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.

  • #9
    Senior Coder jmrker's Avatar
    Join Date
    Aug 2006
    Location
    FL
    Posts
    3,083
    Thanks
    38
    Thanked 498 Times in 492 Posts

    Arrow

    Quote Originally Posted by pratto View Post
    what lessons ? i am not a student asking for help with his homework, i'm just an aging dumbbell trying to understand javascript.

    i'm glad that my comments seem clear, but are they right ?

    thanks
    Sorry for the confusion, but I read this
    I have been watching the crockford videos, and asking some questions in this forum,
    in your first post as if you were following some sort of planned tutorial.

    Never accused you of submitting homework and I figure we are all "aging dumbell"s.

  • #10
    New Coder
    Join Date
    Aug 2013
    Posts
    50
    Thanks
    0
    Thanked 11 Times in 11 Posts
    Quote Originally Posted by jmrker View Post
    my attempt to use the information results in an error message indicating that the function is not found.
    That's because the variable manifest was declared inside the anonymous function (lambda) and it's only visible inside that function.
    Just move your onload function inside that anonymous function. Then you'll have to invoke it, because it doesn't even get executed as of now.




    Quote Originally Posted by jmrker View Post
    I figure we are all "aging dumbell"s.
    I suppose I've been writing in this language since 2007 and I still love learning about it.

  • #11
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,438
    Thanks
    75
    Thanked 4,372 Times in 4,337 Posts
    Quote Originally Posted by joesimmons View Post
    I've been writing in this language since 2007 ...
    Oh, a real newcomer!

    I admit, I didn't get started in it until late 1998 or early 1999, so I'm not an old-timer at it.

    (I did see a presentation of "Mocha" at Netscape, before it was renamed "LiveScript" which then later became "JavaScript", but I didn't actually start using it until three years later.)
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.

  • #12
    New Coder
    Join Date
    Aug 2013
    Posts
    50
    Thanks
    0
    Thanked 11 Times in 11 Posts
    I was only born in 1990 so I wasn't old enough to be interested in that stuff then, you know, lol.

    The story as to why JavaScript has that name is pretty funny.

  • #13
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,438
    Thanks
    75
    Thanked 4,372 Times in 4,337 Posts
    Too bad they didn't stick with "Mocha". Of course, all along that was a play on "Java". But then, if Java had stuck with ITS original name ("Oak") then maybe now we would be coding in "Acorn".
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.

  • #14
    New Coder
    Join Date
    Aug 2013
    Posts
    50
    Thanks
    0
    Thanked 11 Times in 11 Posts
    OakScript! Haha.

  • #15
    Senior Coder jmrker's Avatar
    Join Date
    Aug 2006
    Location
    FL
    Posts
    3,083
    Thanks
    38
    Thanked 498 Times in 492 Posts

    Question

    Quote Originally Posted by joesimmons View Post
    That's because the variable manifest was declared inside the anonymous function (lambda) and it's only visible inside that function.
    Just move your onload function inside that anonymous function. Then you'll have to invoke it, because it doesn't even get executed as of now.
    I moved it inside the function.
    I thought the onload would invoke it, but nothing happened.

    What is the action to invoke it and see some output via the alert?


  •  
    Page 1 of 3 123 LastLast

    Posting Permissions

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