Last active
November 2, 2017 12:59
-
-
Save gearmobile/79e66341d2d742b784f87b2263d07938 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ----------------------------- | |
// 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