Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/tuchk4/jsproxy
https://github.com/tuchk4/jsproxy
Last synced: 20 days ago
JSON representation
- Host: GitHub
- URL: https://github.com/tuchk4/jsproxy
- Owner: tuchk4
- Created: 2014-06-23T10:55:58.000Z (over 10 years ago)
- Default Branch: master
- Last Pushed: 2014-07-23T19:35:59.000Z (over 10 years ago)
- Last Synced: 2024-10-11T00:24:40.812Z (about 1 month 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()
```