SitePoint Sponsor

User Tag List

Results 1 to 9 of 9
  1. #1
    SitePoint Wizard Pepejeria's Avatar
    Join Date
    Jan 2005
    Location
    Too far up north
    Posts
    1,566
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Interesting JavaScript code

    Check out the following page.

    You will get an alert, nothing existing. But then check out the code and figure out how it is done.

    Have fun!


  2. #2
    SitePoint Evangelist stef25's Avatar
    Join Date
    Nov 2004
    Location
    belgium
    Posts
    465
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    yeah that is weird, some one going to explain?
    I need someone to protect me from
    all the measures they take in order to protect me

  3. #3
    SitePoint Wizard stereofrog's Avatar
    Join Date
    Apr 2004
    Location
    germany
    Posts
    4,324
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    nice joke

  4. #4
    SitePoint Wizard Pepejeria's Avatar
    Join Date
    Jan 2005
    Location
    Too far up north
    Posts
    1,566
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    So lets us know how the "joke" works

  5. #5
    SitePoint Wizard stereofrog's Avatar
    Join Date
    Apr 2004
    Location
    germany
    Posts
    4,324
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    "public", "Class" and other "keywords" there are actually labels and can be arbitrary identifiers (or just omitted). He could have written "foo: bar: " instead of "public: Class:" with exactly the same effect.

  6. #6
    SitePoint Guru Ize's Avatar
    Join Date
    Nov 2005
    Location
    The Netherlands
    Posts
    808
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hm, my code editor marks them down as syntax errors, starting at this line:

    Code:
    private: message = "",
    It makes sense, since Javascript object notation glues name/value pairs together with ":" instead of "=". How is it possible it still works then?

  7. #7
    SitePoint Wizard stereofrog's Avatar
    Join Date
    Apr 2004
    Location
    germany
    Posts
    4,324
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    The syntax is "property: value", where "value" is any expression, including assignment. For example, this

    Code:
    foo = {
    	bar: quux = 123
    }
    will create property "bar" equal to "123" and, as a side effect, assign 123 to the variable "quux".

  8. #8
    SitePoint Wizard Pepejeria's Avatar
    Join Date
    Jan 2005
    Location
    Too far up north
    Posts
    1,566
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You rock stereofrog!


  9. #9
    SitePoint Guru Ize's Avatar
    Join Date
    Nov 2005
    Location
    The Netherlands
    Posts
    808
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by stereofrog View Post
    The syntax is "property: value", where "value" is any expression, including assignment. For example, this

    Code:
    foo = {
    	bar: quux = 123
    }
    will create property "bar" equal to "123" and, as a side effect, assign 123 to the variable "quux".
    Ah, that's clear, thanks


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
  •