[ Web Proxy ]
URL:
Viewing: https://raw.githubusercontent.com/Reaper622/JavaScript-DesignPatterns/master/Proxy/Proxy.md [Back]  [Original]

# 

> 



### 



  

```javascript
// 
class Bags {
  constructor(props) {
    this.name = props;
  }
  getName() {
    return this.name;
  }
}

// 
class Star {
  buyBag(bag) {
    console.log(`${bag.getName()}`);
  }
}

// 
let star = new Star();
star.buyBag(new Bags('Coach')); //Coach
```



```javascript
// 
class Bags {
  constructor(props) {
    this.name = props;
  }
  getName() {
    return this.name;
  }
}

// 
class Assistant {
  constructor(props) {
    this.star = props;
  }
  buyBag(bag) {
    this.star.buyBag(bag);
  }
}

// 
class Star {
  buyBag(bag) {
    console.log(`${bag.getName()}`);
  }
}


// 
let star = new Star();
let assistant = new Assistant(star);
assistant.buyBag(new Bags('Coach')); //Coach
```




### 

loading`src`

```javascript
class ABigImage {
  constructor() {
    this.img = new Image();
    document.body.appendChild(this.img);
  }
  setSrc(src) {
    this.img.src = src;
  }
}

class ProxyImage {
  constructor() {
    this.proxyImage = new Image();
  }

  setSrc(src) {
    let bigImageObj = new ABigImage();
    bigImageObj.img.src = './local.png'; // url 
    this.proxyImage.src = src;
    this.proxyImage.onload = function() {
      bigImageObj.img.src = src;
    }
  }
}

var proxyImage = new ProxyImage();
proxyImage.setSrc('Url')
```

 chrome Network  Disable cache  slow 3G 

![uG2uWQ.gif](https://s2.ax1x.com/2019/09/29/uG2uWQ.gif)

`ABigImage``setSrc`

```
// 
let aImage = new ABigImage();
aImage.setSrc('url')
```

#### 

- 
- 
- 


>  [Demo]()


Web Proxy Viewer  |  New URL  |  Original Page