bind的使用demo

by Mike Lin

HTML

<script src="https://getfirebug.com/firebug-lite-debug.js"></script>

JavaScript

let animal = function(location, age){
  console.log(`I am a ${this.type}, my name is ${this.name}, my home is ${location}, age is ${age}`);
}

let dog = {
  type: 'dog',
  name: 'wangwang'
}

let dogSpeak = animal.bind(dog, 'hangzhou');

dogSpeak(10);