Skip to content

Commit

Permalink
修改decorator模式
Browse files Browse the repository at this point in the history
  • Loading branch information
oylx committed Nov 13, 2019
1 parent 03f514f commit e5a753b
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 14 deletions.
20 changes: 20 additions & 0 deletions designMode/DecoratorPattern/es7EditClass.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
const logWrapper = targetClass => {
let orignRender = targetClass.prototype.render
targetClass.prototype.render = function(){
console.log("before render")
orignRender.apply(this)
console.log("after render")
}
return targetClass
}

@logWrapper
class App {
constructor() {
this.title = 'oylx'
}
render(){
console.log('渲染页面:' + this.title);
}
}
new App().render()
File renamed without changes.
12 changes: 0 additions & 12 deletions designMode/DecoratorPattern/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion designMode/DecoratorPattern/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
"devDependencies": {
"@babel/core": "^7.7.2",
"@babel/plugin-proposal-decorators": "^7.7.0",
"@babel/plugin-transform-runtime": "^7.6.2",
"@babel/preset-env": "^7.7.1",
"babel-loader": "^8.0.6",
"html-webpack-plugin": "^3.2.0",
Expand Down
2 changes: 1 addition & 1 deletion designMode/DecoratorPattern/webpack.config.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const HtmlWebpackPlugin = require('html-webpack-plugin')
module.exports = {
entry: {
app: './es7Decorator.js' // 需要打包的文件入口
app: './es7EditClass.js' // 需要打包的文件入口
},
module: {
rules: [
Expand Down

0 comments on commit e5a753b

Please sign in to comment.