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
// 使用 util.inherits 來繼承 EventEmitter 的方法 | |
const EventEmitter = require('events') | |
const util = require('util') | |
function Greetr () { | |
// 如果我們想要完整繼承 EventEmitter 中的屬性 | |
EventEmitter.call(this) | |
this.greeting = 'someone greet' | |
} |
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
const Emitter = require('events') | |
const eventsConfig = require('./config').events | |
let emtr = new Emitter() | |
emtr.on(eventsConfig.GREET, function () { | |
console.log('Somewhere, someone said hello') | |
}) |
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
const Emitter = require('./emitter') | |
let emtr = new Emitter() | |
emtr.on('greet', function () { | |
console.log('Somewhere, someone said hello') | |
}) | |
emtr.on('greet', function () { | |
console.log('A greeting occurred') |
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
/* eslint-disable */ | |
/** | |
* PATTERN 1 | |
**/ | |
module.exports = function() { | |
console.log('Hello world'); | |
}; |
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
<!-- app.vue --> | |
<template lang="html"> | |
<div class="message"> | |
{{ message }} | |
{{ ok }} | |
</div> | |
</template> | |
<script> |
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
<!DOCTYPE html> | |
<html lang="en"> | |
<head> | |
<meta charset="UTF-8"> | |
<title>Demo Vue</title> | |
<script src="https://unpkg.com/[email protected]/dist/vue.js"></script> | |
<script src="https://unpkg.com/[email protected]/dist/axios.js"></script> | |
</head> | |
<body> |
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
Show hidden characters
{ | |
"presets": [ | |
["latest", { | |
"es2015": { "modules": false } | |
}], | |
"stage-2" | |
] | |
} |
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
const arr = [1, 2, 3] | |
// 原生的 array iterator | |
let nativeIterator = arr[Symbol.iterator]() | |
nativeIterator.next() // {value: 1, done: false} | |
nativeIterator.next() // {value: 2, done: false} | |
nativeIterator.next() // {value: 3, done: false} | |
nativeIterator.next() // {value: undefined, done: true} |
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
// 匯入需要的模組 | |
const express = require('express') | |
const bodyParser = require('body-parser') | |
const cookieParser = require('cookie-parser') | |
const path = require('path') | |
const logger = require('morgan') | |
const mongoose = require('mongoose') | |
const session = require('express-session') | |
const passport = require('./middleware/passport') | |
const MongoStore = require('connect-mongo')(session) // 直接執行並將 session 存進去,logout 後會自動刪除該 document |