SitePoint Sponsor

User Tag List

Results 1 to 13 of 13
  1. #1
    SitePoint Zealot
    Join Date
    May 2007
    Location
    West Midlands, UK
    Posts
    173
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Shocked At Javascript

    Morning to you all,

    I was just going through Javascript, picking up where i left of a month or so ago. I never bothered to learn it when i was learning HTML and CSS, so im doing it now.

    I do alot of stuff in PHP, language wise, comparing the both, Javascript is very loose.

    Im shocked at the ease of use, and ease of learning. Its probably because i already know a programming language.

    The ECMA documentation is horrible to read though!

  2. #2
    SitePoint Wizard wonshikee's Avatar
    Join Date
    Jan 2007
    Posts
    1,223
    Mentioned
    3 Post(s)
    Tagged
    0 Thread(s)
    It's a PITA to debug a complex code...

  3. #3
    SitePoint Wizard silver trophy kyberfabrikken's Avatar
    Join Date
    Jun 2004
    Location
    Copenhagen, Denmark
    Posts
    6,157
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by cascadingstylez View Post
    Im shocked at the ease of use, and ease of learning. Its probably because i already know a programming language.
    It's always easier to learn the second programming language. The first time, you both need to learn how to program and how to program in a specific language. The second time, you only need to learn the language. That is particularly true, when the syntaxes are similar, as the case is between javascript and PHP.

    Be ware though, that javascript is fundamentally different from PHP, in that functions are variables, and it has lexical scope (also called static scope).

    Quote Originally Posted by cascadingstylez View Post
    The ECMA documentation is horrible to read though!
    Specifications usually are. There are plenty of good documentation available by third parties.

  4. #4
    SitePoint Zealot
    Join Date
    May 2007
    Location
    West Midlands, UK
    Posts
    173
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by kyberfabrikken View Post
    It's always easier to learn the second programming language. The first time, you both need to learn how to program and how to program in a specific language. The second time, you only need to learn the language. That is particularly true, when the syntaxes are similar, as the case is between javascript and PHP.
    That makes sense

    Be ware though, that javascript is fundamentally different from PHP, in that functions are variables, and it has lexical scope (also called static scope).
    I have realized this today. I have to break out of the habbit of typing: var $varOne = "Some Variable";. Concatenation gets me sometimes aswell, and it looks like working with floats can be problematic.

    Don't get me started on functions and objects, i know what they are and how to use them, but they seem so different to PHP, i mean Javascript has no classes, thats madness.

    Specifications usually are. There are plenty of good documentation available by third parties.
    Mozilla have a nice spec thats nice and easy to read through.

  5. #5
    SitePoint Wizard wonshikee's Avatar
    Join Date
    Jan 2007
    Posts
    1,223
    Mentioned
    3 Post(s)
    Tagged
    0 Thread(s)
    They have classes and objects, it just looks different.

  6. #6
    SitePoint Wizard silver trophy kyberfabrikken's Avatar
    Join Date
    Jun 2004
    Location
    Copenhagen, Denmark
    Posts
    6,157
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by cascadingstylez View Post
    Don't get me started on functions and objects, i know what they are and how to use them, but they seem so different to PHP, i mean Javascript has no classes, thats madness.
    Some have -- halfway jokingly -- called javascript the first lisp to hit mainstream.

  7. #7
    SitePoint Zealot
    Join Date
    May 2007
    Location
    West Midlands, UK
    Posts
    173
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Think i got it now.

    A function object creates the object, you use the new keyword to create an instance of the object.

    I was confusing the function statement with the function object, they look similar. Pickles the mind for a bit that does.

    If you've mastered the concept of passing functions as arguments to other functions then congratulations! You now understand lambda which basically just means using a function as an argument in a call to another function. Lambda is a pretty big buzzword in functional programming and it gets thrown around a lot. Worse, it gets thrown around like everyone already knows that lambda is using a function in an argument in a call to another function. So if you see something like "Here we'll use a lambda expression" it just means they're passing a function as an argument.
    I think structure wise languages such as PHP seem stronger (i may be wrong) JS seems very loose.

  8. #8
    SitePoint Wizard silver trophy kyberfabrikken's Avatar
    Join Date
    Jun 2004
    Location
    Copenhagen, Denmark
    Posts
    6,157
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by cascadingstylez View Post
    I think structure wise languages such as PHP seem stronger (i may be wrong) JS seems very loose.
    I don't think you can compare the two. They are applied to very different environments; Javascript is usually used for event-based programming, while PHP is used for transaction style scripts. JS is a language with multiple implementations, unlike PHP, where there is only one implementation. At the same time, PHP has borrowed a couple of concepts from compiled languages, such as Java and C. So even if the two (js and PHP, that is) are both very dynamic languages, PHP appears as if it had a type system. Finally, a class based object system is probably less abstract -- thus easier to understand, than a lambda based one. I wouldn't say one is more powerful than the other -- It depends on the context.

  9. #9
    Web-coding NINJA! silver trophy beetle's Avatar
    Join Date
    Jul 2002
    Location
    Dallas, TX
    Posts
    2,900
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Not to mention that JS is object-oriented at it's core, whereas PHP is not

    Code PHP:
     $greeting = "Hello World";
    $greetingLength = strlen( $string );

    vs

    Code JavaScript:
     var greeting = "Hello World"
    greetingLength = greeting.length

    Even something that looks like string literal, is really an object in JavaScript.
    beetle a.k.a. Peter Bailey
    blogs: php | prophp | security | design | zen | software
    refs: dhtml | gecko | prototype | phpdocs | unicode | charsets
    tools: ide | ftp | regex | ffdev




  10. #10
    SitePoint Wizard wonshikee's Avatar
    Join Date
    Jan 2007
    Posts
    1,223
    Mentioned
    3 Post(s)
    Tagged
    0 Thread(s)
    Interestingly enough, every data type is an object in PHP, even ones that appear to be primitive.

  11. #11
    Web-coding NINJA! silver trophy beetle's Avatar
    Join Date
    Jul 2002
    Location
    Dallas, TX
    Posts
    2,900
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Care to elaborate on that?

    Maybe they are handled as objects internally, but none of that is exposed to the language itself. There is no object-like interface for manipulating strings or integers.
    beetle a.k.a. Peter Bailey
    blogs: php | prophp | security | design | zen | software
    refs: dhtml | gecko | prototype | phpdocs | unicode | charsets
    tools: ide | ftp | regex | ffdev




  12. #12
    SitePoint Wizard silver trophy kyberfabrikken's Avatar
    Join Date
    Jun 2004
    Location
    Copenhagen, Denmark
    Posts
    6,157
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by beetle View Post
    Code JavaScript:
     var greeting = "Hello World"
    greetingLength = greeting.length

    Even something that looks like string literal, is really an object in JavaScript.
    Actually, it's not. When you call greeting.length, the string primitive is automatically wrapped in a temporary object of type String, on which the method is invoked. You can see this in action:
    Code:
    >>> var foo = "foo"; foo.test = 42; console.log(foo.test);
    undefined

  13. #13
    Web-coding NINJA! silver trophy beetle's Avatar
    Join Date
    Jul 2002
    Location
    Dallas, TX
    Posts
    2,900
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Curious! Thanks for that insight, kyber.
    beetle a.k.a. Peter Bailey
    blogs: php | prophp | security | design | zen | software
    refs: dhtml | gecko | prototype | phpdocs | unicode | charsets
    tools: ide | ftp | regex | ffdev





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
  •