Skip to content

Item 79: Write Modern JavaScript

要点

  • TypeScript lets you write modern JavaScript whatever your runtime environment. Take advantage of this by using the language features it enables. In addition to improving your codebase, this will help TypeScript understand your code.
  • Adopt ES modules (import/export) and classes to facilitate your migration to TypeScript.
  • Use TypeScript to learn about language features like classes, destructuring, and async/await.
  • Check the TC39 GitHub repo and TypeScript release notes to learn about all the latest language features.

正文

js
function Person(first, last) {
  this.first = first
  this.last = last
}

Person.prototype.getName = function () {
  return this.first + ' ' + this.last
}

const marie = new Person('Marie', 'Curie')
console.log(marie.getName())

💻 playground


js
class Person {
  constructor(first, last) {
    this.first = first
    this.last = last
  }

  getName() {
    return this.first + ' ' + this.last
  }
}

const marie = new Person('Marie', 'Curie')
console.log(marie.getName())

💻 playground

Released under the MIT License.