Skip to content

william-yz/aop.js

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

aop.js

usage

var originFunction = function () {
  return new Promise(function (resolve, reject) {
    console.log('in origin function')
    setTimeout(function () {
      resolve('pass to after')
    }, 1000)
  })
}

var aopi = aop(originFunction)
.before(function a(next) {
  console.log('1')
  next('pass to next')
})
.before(function b(next,a) {
  console.log('here in next :' + a)
  console.log('2')
  next()
})
.before(function (next) {
  console.log('after 2 s')
  setTimeout(next, 2000)
})
.before(function (next) {
  console.log('after 1 s')
  setTimeout(next, 1000)
})
.before(function c(next) {
  console.log('3')
  next()
})
.after(function d(next, b) {
  console.log(b)
  next()
})
.after(function d(next) {
  console.log('after 3 s')
  setTimeout(next, 3000)
})
.end(function () {
  console.log('end')
})

aopi()

About

Javascript aop with before and after

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published