Nordic.js 2014 • Douglas Crockford - The Better Parts

By: Nordic.js

555   9   41807

Uploaded on 10/06/2014

Comments (6):

By gorkemyurt    2017-09-20

Douglas Crockford might have some answers for you; https://www.youtube.com/watch?v=PSGEjv3Tqo0.. It makes the developer favor inheritance over composition.

Original Thread

By Yaggo    2017-09-20

It's possible to write javascript without `this`, a style preferred e.g. by Douglas Crockford, explained in the video below.

https://www.youtube.com/watch?v=PSGEjv3Tqo0

I've also started to write my code mostly without `this`, `class` or `new`, not looking back.

Another related, highly recommend reading: https://medium.com/javascript-scene/the-two-pillars-of-javas...

Original Thread

By anonymous    2017-09-20

This is Douglas Crockford original source as it appears in his slides:

function constructor(spec) {
  let {member} = spec,
      {other} = other_constructor(spec),
      method = function () {
        // member, other, method, spec
      };
  return Object.freeze({
    method,
    other
  });
}

The following example is a more concrete version of Douglas Crockford's Object creation pattern 2014.

Douglas Crockford makes heavy use of ECMAScript 6 features like destructuring etc.!!

Start the code in node.js with following options (enable ES6):

node --harmony --harmony_destructuring demo.js

demo.js

// Douglas Crockford 2014 Object Creation
(function() {
  'use strict';

  function adress(spec) {

    let {
      street, city
    } = spec,
    logAdress = function() {
      console.log('Adress:', street, city);
    };
    return Object.freeze({
      logAdress
    });
  };

  function person(spec) {

    let {
      preName,
      name
    } = spec, {
      logAdress
    } = adress(spec),
      logPerson = function() {
        // member, other, method, spec
        console.log('Name: ', preName, name);
        logAdress();
      };
    return Object.freeze({
      logPerson,
      logAdress
    });
  };


  let myPerson = person({
    preName: 'Mike',
    name: 'Douglas',
    street: 'Newstreet',
    city: 'London'
  });

  myPerson.logPerson();
})();

According to Douglas Crockford’s talk, he avoids the use of:

  • new
  • Object.create
  • this !!!

Watch the original Crockford video: https://www.youtube.com/watch?v=PSGEjv3Tqo0

A good explanation for the Crockford Douglas Object Creation Pattern 2014 is this blog: https://weblogs.asp.net/bleroy/crockford%E2%80%99s-2014-object-creation-pattern

Original Thread

By anonymous    2018-02-05

While Douglas Crockford used to be a zealous advocate of Object.create() and he is basically the reason why this construct actually is in javascript, he no longer has this opinion.

He stopped using Object.create, because he stopped using this keyword altogether as it causes too much trouble. For example, if you are not careful it can easily point to the global object, which can have really bad consequences. And he claims that without using this Object.create does not make sense anymore.

You can check this video from 2014 where he talks at Nordic.js:

https://www.youtube.com/watch?v=PSGEjv3Tqo0

enter image description here

Original Thread

By anonymous    2018-05-09

TypeScript and JavaScript has two nullable types: null and undefined.

Most other languages initially didn't, because it's not a clear-cut win to have the two option types (cf. https://www.youtube.com/watch?v=PSGEjv3Tqo0&feature=youtu.be&t=9m21s from https://basarat.gitbooks.io/typescript/docs/javascript/null-undefined.html; https://github.com/Microsoft/TypeScript/wiki/Coding-guidelines#null-and-undefined).

In Rust you'd use the Option instead, which (most of the time) corresponds to both the null and undefined of JavaScript and TypeScript.

struct Example {
    value1: String,
    optional: Option<i64>,
    value3: Option<String>
}

P.S. In order to specify just the fields you want to specify, and leave all the other fields at None, you can tell the language to implement the Default for the struct:

#[derive(Default)]
struct Example {
    value1: String,
    optional: Option<i64>,
    value3: Option<String>
}

fn new_example() -> Example {
    Example {
        value1: "foobar".into(),
        ..Default::default()
    }
}

Original Thread

Submit Your Video

If you have some great dev videos to share, please fill out this form.