js--call( )/apply()/bind()--应用
2024-10-13 11:18:18
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/call
function Product(name, price) {
this.name = name;
this.price = price;
} function Food(name, price) {
Product.call(this, name, price);
this.category = 'food';
} function Toy(name, price) {
Product.call(this, name, price);
this.category = 'toy';
} var cheese = new Food('feta', 5);
var fun = new Toy('robot', 40);
var animals = [
{ species: 'Lion', name: 'King' },
{ species: 'Whale', name: 'Fail' }
]; for (var i = 0; i < animals.length; i++) {
(function(i) {
this.print = function() {
console.log('#' + i + ' ' + this.species
+ ': ' + this.name);
}
this.print();
}).call(animals[i], i);
}
function greet() {
var reply = [this.person, 'Is An Awesome', this.role].join(' ');
console.log(reply);
} var i = {
person: 'Douglas Crockford', role: 'Javascript Developer'
}; greet.call(i); // Douglas Crockford Is An Awesome Javascript Developer
最新文章
- 重量级Orchard模块发布 - 模块生成工具RaisingStudio.ModuleGenerator
- Error:&ldquo;应用程序无法正常启动(0xc000007b)。请单击&ldquo;确定&rdquo;关闭应用程序。&rdquo;
- iOS开发编译报错、常见问题(实时更新)
- java学习第9天
- dd 生成指定大小文件
- Oboe 提升web 用户体验以及性能
- java开发常用命令
- Docker系列之(一):10分钟玩转Docker(转)
- SQLServer修改数据列
- imx6 工具链下载地址
- [leetcode]7. Reverse Integer反转整数
- centos7使用kubeadm配置高可用k8s集群
- linux 如何快速的查找日志中你所要查找的信息
- widget jquery 理解
- linux下的usb转串口的使用(修改)【转】
- javascript 完美解决对联广告
- BZOJ 2745: [HEOI2012]Bridge
- SQL: 查找空值
- 转:如何转换Android打包用jks格式keystore证书为Air用pkcs12格式p12证书
- JXM 监控tomcat 7(含代码
热门文章
- 62. Unique Paths不同路径
- 2017-3-31/socket
- 牛客网 PAT 算法历年真题 1001 : A+B和C (15)
- 微信小程序自动定位,通过百度地图根据经纬度获取该地点所在城市信息
- 把旧系统迁移到.Net Core 2.0 日记(11) -- Authentication 认证 claimsIdentity 对比 之前的FormAuthentication
- python(6)之文件
- Node.js是用来干嘛的
- 基本git指令
- laravel基于Bootstrap的成功和失败的提示信息和验证提示信息
- shell 流程控制语句