SitePoint Sponsor

User Tag List

Page 1 of 2 12 LastLast
Results 1 to 25 of 26
  1. #1
    SitePoint Addict NetNerd85's Avatar
    Join Date
    Aug 2005
    Location
    Australia
    Posts
    298
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question Learning the javascript mindset

    Greetings all,

    It's all about the mindset. I would like to learn javascript but am having trouble grasping the correct mindset. I know HTML, CSS and PHP, so knowing PHP gives me a platform to build on. I have been coding HTML/CSS for years.. so there is no trouble there.

    So my question is, does anyone have any tips for grasping the mindset for learning and using javascript?


    Please remember, everyone learns differently
    a new day, a new beginning
    never follow the crowd, the crowd is poor!

  2. #2
    SitePoint Addict
    Join Date
    Dec 2007
    Posts
    358
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Try jQuery - I think that it perfectly demonstrates what is JS for and how to use it.
    I'm creating trouble-free Apache, PHP, MySQL installer, WITSuite,
    and use it to setup my development environment.
    Demo, support, contact. Questions?

  3. #3
    SitePoint Addict NetNerd85's Avatar
    Join Date
    Aug 2005
    Location
    Australia
    Posts
    298
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I am familiar with jQuery and other frameworks. I am not asking about frameworks but thank you for the reply. I am asking about how other people have taught themselves javascript and what specifically they had to realize in order to think as a javascript programmer. There are specific ways html coders, css coders and php programmers think in order to code.
    a new day, a new beginning
    never follow the crowd, the crowd is poor!

  4. #4
    Function Curry'er JimmyP's Avatar
    Join Date
    Aug 2007
    Location
    Brighton, UK
    Posts
    2,006
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Well, I started out with HTML/CSS and then picked up some basic PHP along the way. Eventually I had an intermediate level of PHP and decided to have a look at JavaScript thinking that it couldn't be that much harder to learn than PHP.

    I'm not a complete wiz at JavaScript (yet...) and I don't grasp many of the more advanced concepts completely but I get by nicely with the knowledge that I have.

    To be honest I don't think there is a particular mindset unique to JavaScript. I think the fact that you have experience with PHP will help you with the syntax and your knowledge of HTML/CSS will help you in learning about and manipulating the DOM.

    I'm sure you know that there are tonnes of tutorials and books available so maybe that's an option?

    I think the way I code could be called progressive; I rarely plan something out... I just start and see where it takes me - That's part of the "enjoyment" of it. I chose to start with the basics and build up my skills through application and practice - you could do this... or you could learn everything straight away (would take a while).
    James Padolsey
    末末末末末末末末末末末末末末末末末末末
    Awesome JavaScript Zoomer (demo here)
    'Ajaxy' - Ajax integration solution (demo here)

  5. #5
    SitePoint Guru
    Join Date
    Apr 2006
    Posts
    802
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Write code, test code, rewrite code.
    mindset?
    write more code.

  6. #6
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,684
    Mentioned
    99 Post(s)
    Tagged
    4 Thread(s)
    Keep the javascript seperate from the html, even for attaching events.

    Use as few identifiers and class names as possible, and stay away from global variables.

    Read the Core Javascript 1.5 Guide at the Mozilla Developer Center

    Study how Douglas Crockford uses javascript and watch the Yahoo Javascript Videos

    Get your head around the this keyword

    For more advanced stuff, the quirksmode website and crockfords javascript: the good parts are excellent resources
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript

  7. #7
    SitePoint Zealot Ken Sharpe's Avatar
    Join Date
    Apr 2008
    Posts
    160
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    The thing that got me about javascript was closures and the concept of prototyping. If you get those, you'll be almost there. Also, get comfortable with weakly typed function pointers.

  8. #8
    SitePoint Enthusiast Grayson's Avatar
    Join Date
    Jun 2008
    Posts
    76
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    The absolute best source for BEG-INTERMED JavaScript is Simply JavaScript. I have read it front to back 3 times and have more stickies in that guy than most of my other books. Excellent reference and read. I am moving on to Pro JavaScript and JavaScript Design patterns.

  9. #9
    Programming Since 1978 silver trophybronze trophy felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, NSW, Australia
    Posts
    16,788
    Mentioned
    25 Post(s)
    Tagged
    1 Thread(s)
    "JavaScript: The Good Parts" by Douglas Crockford is an excellent book for intermediate-advanced programmers to tell them what parts of JavaScript to avoid using in order to improve their code and get rid of most of the common bug sources and inefficiencies and use JavaScript as a proper language.
    Stephen J Chapman

    javascriptexample.net, Book Reviews, follow me on Twitter
    HTML Help, CSS Help, JavaScript Help, PHP/mySQL Help, blog
    <input name="html5" type="text" required pattern="^$">

  10. #10
    SitePoint Addict NetNerd85's Avatar
    Join Date
    Aug 2005
    Location
    Australia
    Posts
    298
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Bad Books

    Nearly all of the books about JavaScript are quite awful. They contain errors, poor examples, and promote bad practices. Important features of the language are often explained poorly, or left out entirely. I have reviewed dozens of JavaScript books, and I can only recommend one: JavaScript: The Definitive Guide (5th Edition) by David Flanagan. (Attention authors: If you have written a good one, please send me a review copy.)

    From: http://javascript.crockford.com/javascript.html
    So that is the one I bought last night and OMG. He is absolutely correct, as I own two javascript books and they are absolute turd in comparison. Yes I have also looked at many of the sitepoint books (a friend loves them), I don't like the format many follow.

    Felgall I will look out for Crockfords book when I get up to that stage, cheers.

    pmw57 thanks for the link to the crockford website where I located this book I now love.

    The thing about javascript (as David Flanagan says) it's not easy, if you want to do things properly and sadly most javascript code is dreadful to look at. Online references are rarely ever detailed enough to cover a programming language, sadly. They dont cover enough of the do's and don'ts. Looking at other peoples javascript code to learn it, is like cutting your eyes lids then rubbing some salt in them when you take a look at someone else's code which is written with totally different "standards".

    It is so very refreshing to pick up a Javascript book and read from someone who knows what they are really talking about.

    Anyone else read JavaScript: The Definitive Guide (5th Edition) by David Flanagan? I started reading part 1 but skipped to part 2 because I want to learn the context in which javascript is to play before the language rules (of course I will read part 1). Has anyone else done this?
    a new day, a new beginning
    never follow the crowd, the crowd is poor!

  11. #11
    Programming Since 1978 silver trophybronze trophy felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, NSW, Australia
    Posts
    16,788
    Mentioned
    25 Post(s)
    Tagged
    1 Thread(s)
    The fifth edition of JavaScript the definitive guide contains really antiquated HTML. Does anyone know if he's released a more recent version that actually has HTML in it that follows the standards?

    It is really hard to write JavaScript that interacts with the HTML properly when you have C.R.A.P. instead of H.T.M.L.
    Stephen J Chapman

    javascriptexample.net, Book Reviews, follow me on Twitter
    HTML Help, CSS Help, JavaScript Help, PHP/mySQL Help, blog
    <input name="html5" type="text" required pattern="^$">

  12. #12
    SitePoint Addict NetNerd85's Avatar
    Join Date
    Aug 2005
    Location
    Australia
    Posts
    298
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by felgall View Post
    The fifth edition of JavaScript the definitive guide contains really antiquated HTML. Does anyone know if he's released a more recent version that actually has HTML in it that follows the standards?

    It is really hard to write JavaScript that interacts with the HTML properly when you have C.R.A.P. instead of H.T.M.L.
    Perhaps you can give me a page number as it seems fine to me. If you dont like bad programmer HMTL, never touch a PHP book
    a new day, a new beginning
    never follow the crowd, the crowd is poor!

  13. #13
    SitePoint Addict NetNerd85's Avatar
    Join Date
    Aug 2005
    Location
    Australia
    Posts
    298
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hrmmm, guess not

    Any way, "Event Driven"

    JavaScript is event driven, the user must interact with the web page in order for something to happen. JavaScript can use events to call functions which in turn manipulate HTML code. JavaScript is a layer on top of HTML/CSS not under it like PHP.

    An example of JavaScript. You have a list of forum categories with the forum topics with-in each category. You use PHP to retrieve the list from the database which creates a HTML page, you then use JavaScript to add in interactive functionality that enables you to "collapse" each forum category hiding the forum topics. This can save space and make viewing of the web page easier for the user.

    ... Sometimes I over think things when the answer is right in front of my face. Now I can enjoy this language which for some reason I was afraid to explore for a few years. Well, I think it was other peoples use of the language which "scared me" - since the language is looser than a town bike it's much easier to be a nasty coder with no standards.

    a new day, a new beginning
    never follow the crowd, the crowd is poor!

  14. #14
    Floridiot joebert's Avatar
    Join Date
    Mar 2004
    Location
    Kenneth City, FL
    Posts
    823
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    If you always consider Javascript a "bolt on" or "accessory", it's tough to go wrong.
    A site should be able to function without Javascript, and if JS is available the JS should be used to enhance the user experience.

  15. #15
    Programming Since 1978 silver trophybronze trophy felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, NSW, Australia
    Posts
    16,788
    Mentioned
    25 Post(s)
    Tagged
    1 Thread(s)
    Quote Originally Posted by NetNerd85 View Post
    Perhaps you can give me a page number as it seems fine to me. If you dont like bad programmer HMTL, never touch a PHP book
    page 4 script tag missing type="text/javascript"
    page 7 style tag missing type="text.css"
    page 8 form is missing label tags to label the input fields
    page 8 language="javascript" should be type="text/javascript"
    page 10 missing type="text/javascript"

    those are the HTML errors in chapter one. The rest of the chapters are similarly full of HTML errors.
    Stephen J Chapman

    javascriptexample.net, Book Reviews, follow me on Twitter
    HTML Help, CSS Help, JavaScript Help, PHP/mySQL Help, blog
    <input name="html5" type="text" required pattern="^$">

  16. #16
    om nom nom nom Stomme poes's Avatar
    Join Date
    Aug 2007
    Location
    Netherlands
    Posts
    10,271
    Mentioned
    50 Post(s)
    Tagged
    2 Thread(s)
    If you always consider Javascript a "bolt on" or "accessory", it's tough to go wrong.
    A site should be able to function without Javascript, and if JS is available the JS should be used to enhance the user experience.
    Amen brothah. A page that cannot function without JS is either broken, or not a web page but an application. My ever-so-humble opinion, of course.

    Now this may be overkill, but my husband, who went and learned Assembler because he decided you can't write truly optimised code if you don't really know what a computer does with it, as told me to read the ANSI C book by Don Knuth. I have the Simply Javascript book, and I already like the little bitty bit I've started with as it's totally stressing seperation of behaviours and basic stupid things like What is a Statement etc. My husband says the true basics of good programming are the same (pretty much) between all languages and so I've better get those drilled into my head first thing, even if it's a C book.
    He also wants me to read Write Great Code by Randall Hyde. Not sure if I can actually get anything out of that, I'm too newb.

    I say this because as I understand it you can write lots of (working) PHP and not have basics of good programming down at the same time, and I guess you could do that with JS too but better to get a good "programming mindset" since that's what you'd want for a "javascript mindset". If you already have a good programming mindset (understand the pitfalls of not having namespaces for example that PHP does) then you should be good for any language thrown at you.

  17. #17
    SitePoint Addict NetNerd85's Avatar
    Join Date
    Aug 2005
    Location
    Australia
    Posts
    298
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    The book series "Write Great Code by Randall Hyde" does indeed looks brilliant. Has anyone read the whole series?

    Quote Originally Posted by felgall View Post
    page 4 script tag missing type="text/javascript"
    page 7 style tag missing type="text.css"
    page 8 form is missing label tags to label the input fields
    page 8 language="javascript" should be type="text/javascript"
    page 10 missing type="text/javascript"

    those are the HTML errors in chapter one. The rest of the chapters are similarly full of HTML errors.


    In his book he explains the differences between language="javascript" and type="text/javascript". He does not write them in the first chapter so he doesn't have to explain them to noobs and it is, a book with concise quick examples. In the text he says you can leave out the html tags for a quick test... yes, to test not write a professional document for a client. I don't understand why you would attack a book for such minor things considering the large amounts of filth written in other books.
    a new day, a new beginning
    never follow the crowd, the crowd is poor!

  18. #18
    I meant that to happen silver trophybronze trophy Raffles's Avatar
    Join Date
    Sep 2005
    Location
    Tanzania
    Posts
    4,662
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    In JavaScript you can do this:

    Code JavaScript:
    var words = 'this is a string'.replace(' a ', ' my ').split(' ');
    While in PHP:
    Code PHP:
    $words = explode(" ", str_replace(" a ", " my", "this is a string"));
    A matter of preference perhaps, but I love the dot notation. It just makes everything flow better in my head and look cleaner, more logical and far more readable. Also, it makes the "ownership" of the string methods to a string object very clean and logical as well (that's something else I like, that everything is an object), whereas in PHP all the functions are just standalone things where you just chuck everything into the arguments (which can be very confusing, e.g. the order you put args into str_replace).

  19. #19
    SitePoint Enthusiast kceleb9's Avatar
    Join Date
    Jun 2008
    Posts
    40
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    STRONGLY agree with alex above - if your mindset is still fresh - start with something VERY smart like jquery.

    main problem with Javascript - and why it was derided as a toy for so long - is that it is easy for a developer to become sloppy - and start spraying code all over the place. It will do something - but it will not be good engineering or programming. It will lead to heartache.

    In the old days - everone started by adding "onclick" handlers to buttons and divs - and other events - and small scripts hanging off them... there has been a big (and smart) reaction against that from the "unobtrusive javascript" crowd - it is a long history.

    Given that you are starting fresh - take a look at Jquery and other libraries that can really ease the pain - and also help you develop a healthy mindset.

  20. #20
    om nom nom nom Stomme poes's Avatar
    Join Date
    Aug 2007
    Location
    Netherlands
    Posts
    10,271
    Mentioned
    50 Post(s)
    Tagged
    2 Thread(s)
    main problem with Javascript - and why it was derided as a toy for so long - is that it is easy for a developer to become sloppy - and start spraying code all over the place.
    It sure seems the same way with PHP, but the attitude there was never so bad as with JS... more like, PHP=greatest thing since sliced bread. I do have hopes for PHP6 though.

    I need to correct myself, my ANSI C book isn't Knuth's but Dennis Ritchie and Brian Kerninghan.

  21. #21
    Guru in training bronze trophy SoulScratch's Avatar
    Join Date
    Apr 2006
    Location
    Maryland
    Posts
    1,838
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    The fifth edition of JavaScript the definitive guide contains really antiquated HTML. Does anyone know if he's released a more recent version that actually has HTML in it that follows the standards?

    It is really hard to write JavaScript that interacts with the HTML properly when you have C.R.A.P. instead of H.T.M.L.
    And this site's markup is not antiquated?

    <div align="center"><script type="text/javascript" src="inc/topad.js"></script><noscript>
    <span class="head">Search: <input type='text' size='35' name='s_n' />
    <div id="a1" class="mes"><div style="color:#000099;font-weight:700;font-family:georgia,serif;font-size:1.5em;text-align:center;">
    <script type="text/javascript" language="JavaScript1.2" src="inc/mytime1.js"></script>
    I remember Definitive having better markup than this.

  22. #22
    Guru in training bronze trophy SoulScratch's Avatar
    Join Date
    Apr 2006
    Location
    Maryland
    Posts
    1,838
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Raffles View Post
    In JavaScript you can do this:

    Code JavaScript:
    var words = 'this is a string'.replace(' a ', ' my ').split(' ');
    While in PHP:
    Code PHP:
    $words = explode(" ", str_replace(" a ", " my", "this is a string"));
    A matter of preference perhaps, but I love the dot notation. It just makes everything flow better in my head and look cleaner, more logical and far more readable. Also, it makes the "ownership" of the string methods to a string object very clean and logical as well (that's something else I like, that everything is an object), whereas in PHP all the functions are just standalone things where you just chuck everything into the arguments (which can be very confusing, e.g. the order you put args into str_replace).
    Yes, I agree, PHP looks like a bunch of random *** functions hacked in together with inconsistent naming, I adore modern, elegant JS syntax

  23. #23
    SitePoint Zealot loathsome's Avatar
    Join Date
    Jul 2008
    Location
    Norway
    Posts
    121
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I actually never really "learned" JavaScript. I just messed around with it, until I eventually got the hang of it. Later on I moved to the Prototype-library, and loved it. These days I'm sticking with jQuery though. Libraries really have changed the way I write JavaScript I can't recommend jQuery enough.
    Time you enjoy wasting is not wasted time.

    Loathsome Systems

  24. #24
    SitePoint Addict NetNerd85's Avatar
    Join Date
    Aug 2005
    Location
    Australia
    Posts
    298
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by SoulScratch View Post
    And this site's markup is not antiquated?

    Code:
    <div align="center"><script type="text/javascript" src="inc/topad.js"></script><noscript>
    I remember Definitive having better markup than this.
    a new day, a new beginning
    never follow the crowd, the crowd is poor!

  25. #25
    Designer
    Join Date
    Jun 2006
    Location
    Manila
    Posts
    590
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    All I can say is...

    The more you learn "hard" Javscript, the more you realize how awesome jQuery is.


Bookmarks

Posting Permissions

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