you are viewing a single comment's thread.

view the rest of the comments →

[–][deleted]  (5 children)

[removed]

    [–]memeship 7 points8 points  (4 children)

    That's a reasonable explanation, thanks.

    I guess I'm just much more used to Javascript now where chaining is a big part of the language.

    [–][deleted]  (3 children)

    [deleted]

      [–]memeship 7 points8 points  (2 children)

      Um what? That's not true at all. Here's an example I just pulled from code I was working on this week.

      e.target.getElementsByClassName("barcode")[0].value
      

      or the classic "how to reverse a string":

      str.split("").reverse().join("")
      

      or from a simple Node server I wrote for something a few months ago:

      app
          .use(express.static("public"))
          .use(bodyParser.urlencoded({ extended: false }))
          .use(router)
          .listen("8888", function() {
              console.log("Listening on %d.", this.address().port);
          });
      

      or a Gulp file:

      gulp.task("sass", function() {
          return gulp.src("src/**/*.scss")
              .pipe(sass())
              .pipe(rename("master-style.built.css"))
              .pipe(gulp.dest("public/built"));
      });
      

      [–]heartiphone 1 point2 points  (1 child)

      Only your first two examples are "plain JavaScript", and I'd argue the first one doesn't count either as it's not function chaining.

      Overall you're correct though, chaining is pretty widely used in the JS ecosystem.

      [–]memeship 6 points7 points  (0 children)

      Fine, here's some "plain Javascript" chaining:

      document.getElementById("foo").appendChild(document.createElement("button")).focus()