12 votes

Dissecting A Dweet ~ Spiral Javascript Quine Explained

4 comments

  1. KilledByAPixel
    Link
    Hi, Tildes folks! Over the past few months I've written several hundred tiny JavaScript programs to do all kinds of cool stuff. Most of these programs are 140 characters or less and I've learned a...

    Hi, Tildes folks! Over the past few months I've written several hundred tiny JavaScript programs to do all kinds of cool stuff. Most of these programs are 140 characters or less and I've learned a ton about this very niche skill.

    My plan is to start publishing short articles about how some of these work. I hope others find this style of "tiny coding" as fascinating as I do.

    I chose to write about this spiral quine I did first because it is one of the easier to follow ones and has a really beautiful result. This one came to me in a dream, no joke. I also made a really fun animation to help demonstrate how the code works.

    Thanks for reading!

    5 votes
  2. [3]
    Bauke
    Link
    Great post! I love going on Dwitter every now and then and looking at all the cool things people have made so definitely keep it up! I love the explanations too. :) This kind of had me puzzled for...

    Great post! I love going on Dwitter every now and then and looking at all the cool things people have made so definitely keep it up! I love the explanations too. :)

    The u here refers to the code for the function itself.

    This kind of had me puzzled for a bit because u is the actual function so I was wondering how you get the source code from it and discovered that functions in JavaScript have a .toString() that you can call and it prints the source code. Which I guess is what happens under the hood of fillText(). :D

    4 votes
    1. [2]
      KilledByAPixel
      Link Parent
      Thank you! This was one of the more straightforward dweets I've done, working up to explaining some of the more crazy stuff. So, about the text of u, it is even simpler then that. In javascript...

      Thank you! This was one of the more straightforward dweets I've done, working up to explaining some of the more crazy stuff.

      So, about the text of u, it is even simpler then that. In javascript any time you try to do a string operation on something that is not a string, it will be automatically converted to a string. So it's not just fillText, but any function or operator that will do this.

      3 votes
      1. Bauke
        Link Parent
        I thought that too but I've never seen it actually print the source code, I've only ever seen it like this: > (function boop() {}) < [Function: boop] Similar to how it happens with objects: >...

        I thought that too but I've never seen it actually print the source code, I've only ever seen it like this:

        > (function boop() {})
        < [Function: boop]
        

        Similar to how it happens with objects:

        > ({}).toString()
        < '[object Object]'
        

        I was also playing around with it for a bit and found that you can do .toString() on the toString function and then it returns something like this:

        > (() => {}).toString.toString()
        < "function toString() {\n[native code]\n}"
        
        3 votes