Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 'use strict'
- function Obj() {}
- Obj.prototype.getVal = getVal
- Obj.prototype.clearCache = function clearCachedVal() {
- console.log('clearing the cache')
- this.getVal = getVal
- }
- function getVal(x) {
- var _val
- console.log('setting cached data')
- this.getVal = function getCachedVal() {
- console.log('serving cached data')
- return _val
- }
- //do stuff with _val
- _val = x
- return _val
- }
- var obj = new Obj()
- console.log(obj.getVal(1))
- console.log(obj.getVal(2))
- obj.clearCache()
- console.log(obj.getVal(2))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement