Skip to content

Instantly share code, notes, and snippets.

@gearmobile
Last active November 2, 2017 12:59
Show Gist options
  • Save gearmobile/79e66341d2d742b784f87b2263d07938 to your computer and use it in GitHub Desktop.
Save gearmobile/79e66341d2d742b784f87b2263d07938 to your computer and use it in GitHub Desktop.
// -----------------------------
// export and import modules
// -----------------------------
// uno.js
const uno = {
value: 1
}
export default uno
// ---
import first from './uno.js'
// duo.js
const one = {
value: 1
}
const two = {
value: 2
}
export const one
export const two
// импортировать жестко по имени
import { one } from './duo.js'
import { two } from './duo.js'
// импортировать как alias
// ---
import { one as Primo } from './duo.js'
import { two as Secondo } from './duo.js'
// все экспортируемые из файла duo.js константы преобразуются в свойтсва объекта bundle
import * as bundle from './duo.js'
// =>
bundle {
one: one
two: two
}
// ----------------------
// es6
// ----------------------
class Human {
constructor () {
this.gender = 'male'
}
printGender () {
console.log(this.gender)
}
}
class Person extends Human {
constructor () {
super()
this.name = 'Max'
}
printName () {
console.log(this.name)
}
}
// ---
const person = new Person()
person.printName();
person.printGender();
// ---------------------------
// es7
// ---------------------------
class Human {
gender = 'male'
printGender = () => {
console.log(this.gender)
}
}
class Person extends Human {
name = 'Max'
printName = () => {
console.log(this.name)
}
}
// ---
const person = new Person()
person.printName();
person.printGender();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment