https://github.com/tuchk4/jsproxy
https://github.com/tuchk4/jsproxy
Last synced: 4 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/tuchk4/jsproxy
- Owner: tuchk4
- Created: 2014-06-23T10:55:58.000Z (about 11 years ago)
- Default Branch: master
- Last Pushed: 2014-07-23T19:35:59.000Z (almost 11 years ago)
- Last Synced: 2025-02-06T07:46:39.990Z (5 months ago)
- Language: JavaScript
- Size: 168 KB
- Stars: 2
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
JS Proxy
=======#Goal
Call object's methods from another object
```javascript
return new Proxy({
// closure for creating object for proxying
$create: function(){
...
},// array of the methods that should be proxied
$methods: [...],// additional methods
cancel: function(){
...
}
});
```Example:
Proxy methods from angularjs $http service and add custom `cancel` method:```javascript
var canceler = $q.defer();
var p = new Proxy({
$create: function(){
return $http({
...
timeout: canceler.promise
});
},$methods: ['then', 'catch', 'finally'],
cancel: function(){
return canceler.resolve();
}
});// methods form $http service
p.then(...)
p.catch(...)
p.finally(...)// custom method
p.cancel()
```