r/javascript • • Jul 23 '16

[Project] fart.io (suggestions welcome)

https://github.com/toiletjs/fart.io
9 Upvotes

18 comments sorted by

7

u/Pantstown (pants) => (town) => pantstown Jul 23 '16

.silentButDeadly() --> no logs, crashes browser

5

u/brexitjs Jul 23 '16 edited Jul 23 '16

I like it. I feel like it's more of an instance property than method though? Something like this (off the top of my head):

constructor(opt_isWet, opt_isSilentButDeadly)

Not sure how to crash the browser though. I can add a TODO and throw an error for now.

Edit: Tracking this in https://github.com/toiletjs/fart.io/issues/5 for now.

2

u/Pantstown (pants) => (town) => pantstown Jul 23 '16 edited Jul 23 '16

As we all know, although a shart may be deadly, a shart can never be silent. Therefore, it stands to reason that only a fart can be both silent and deadly.

class Fart extends AbstractBaseFart {
    /**
     * Farts.
     */
    fart() {
        if (this.isSilent && this.isDeadly) {
            while(true){} // will crash tab
        } else {
            if (this.isWet) {
                console.log('pfffffpfpfpffffff?');
            } else {
                console.log('poooOOOot.');
            }
        }
    }
}

let myFart = new Fart();
myFart.isSilent = true;
myFart.isDeadly = true;
myFart.fart()

Or you can just have a method that runs that code:

SBD() {
    while(true){}
}

2

u/brexitjs Jul 23 '16

Nice! I started to integrate this feature by adding a new "class FatalFart extends Error" and throwing that after a predetermined MTTW (mean time to waft). Although the weakness of this approach is obviously that by delaying the exception (in a setTimeout, for example) the callback becomes asynchronous and fails to fatally interrupt the application. An infinite loop is a great suggestion that should definitely have the desired side effects! Thanks!

2

u/brexitjs Jul 23 '16

Serious question though, how would you test it?

2

u/bogdan5844 Jul 23 '16

Would blocking the JS thread so that no DOM updates are made be a way to "crash" the browser ?

5

u/Nebril Jul 23 '16

Literally a shitpost. Well played.

3

u/brexitjs Jul 23 '16

Yeah it's a silly subject but I'm learning a lot about ES6 in the process. I think I mentioned it in another reply but this project was the first time I got to use the new class syntax. I'm taking it seriously as a learning experience. I didn't mean for it to be a shitpost.

2

u/mick0n Jul 23 '16

I feel that fart.io may be lacking a definition of input. The output fart may depend on what framework was used as input, i.e. beansJS may produce a more explosive output than say rice.io (Which may override console.log and thus silence output completely)

2

u/brexitjs Jul 23 '16

That's definitely a concern. WDYT of using something like the decorator pattern to wrap fart.io with framework-specific IO implementations? (accepting pull requests as well, nudge nudge ;)

3

u/Dmnevius Jul 23 '16

Revolutionary framework. Definitely going to use this in my next project. Keep up the good work!

2

u/brexitjs Jul 23 '16

Thanks! Changed to ES6 with an AbstractBaseFart and a Shart subclass. First time using class syntax but definitely a joy; much easier than dealing with prototypes!

2

u/saadq_ Jul 24 '16

Since you seem to be new to ES6, just want to point out that you're still actually using prototypes. The class syntax is just sugar over it, so if you do something like:

class Car {
  constructor (color, mileage) {
    this.color = color
    this.mileage = mileage
  }

  paint (color) {
    this.color = color
  }

  drive (miles) {
    this.mileage += miles
  }
}

It's simply syntax sugar for this behind the scenes:

function Car (color, mileage) {
  this.color = color
  this.mileage = mileage
}

Car.prototype.paint = function (color) {
  this.color = color
}

Car.prototype.drive = function (miles) {
  this.mileage += miles
}

So even if you use the class syntax, you can still add on methods to the prototype dynamically, etc. So ES6 classes aren't really "blueprints" of an object like you might be accustomed to from a language like Java or something similar.

1

u/brexitjs Jul 24 '16

Helpful, thanks! The MDN docs I looked up did mention that it's all still prototypes in the background but this is a good example to reinforce that it can be written both ways.

17

u/joshmanders Full Snack Developer Jul 23 '16

I giggled, but I looked into your post history and found brexitjs, and well that's just genius.

var GB = document.querySelector('script[src$=brexit.js]');
var EU = GB.parentNode;
EU.removeChild(GB);

4

u/iRuisu Jul 24 '16 edited Jan 08 '17

[deleted]
0.6506

What is this?

10

u/veswill3 Jul 23 '16

// Note that this.isWet is not checked here as all sharts are considered wet.

Legit.

4

u/bogdan5844 Jul 23 '16

A React-based JS framework that makes farts.

  • TODO(toiletjs): Use React. See #4 (v2).

Something's smelly here.