* Function.prototype.bind

Function.prototype.bind = function() {
var self = this,
context = [].shift.call(arguments),
args = [].slice.call(arguments);
return function() {
return self.apply(context, [].concat.call(args, [].slice.call(arguments)));
}
}

 // test

// test
var obj = {
name: 'mingzhanghui'
};
var func = function(a, b, c, d) {
console.log(this.name);
console.log([a,b,c,d]);
}.bind(obj, 1, 2); func(3,4);

  

* Array.prototype.map

Array.prototype.map = function(callback) {

	var T, A, k;
if (this == null) {
throw new TypeError('this is null or not defined');
}
var O = Object(this);
var len = O.length >>> 0; if (typeof callback !== 'function') {
throw new TypeError(callback + ' is not a function');
}
if (arguments.length > 1) {
T = arguments[1];
}
A = new Array(len);
k = 0; while (k < len) {
var kValue, mappedValue;
if (k in O) {
kValue = O[k];
mappedValue = callback.call(T, kValue, k, O);
A[k] = mappedValue;
}
k++;
}
return A;
};

  

javascript 一些函数的实现 Function.prototype.bind, Array.prototype.map的更多相关文章

  1. javascript匿名函数自执行 (function(window,document,undefined){})(window,document);

    使用匿名自执行函数的作用: (function(window,document,undefined){})(window,document); 1.首先匿名函数 (function(){}) (); ...

  2. Array.prototype.slice && Array.prototype.splice 用法阐述

    目的 对于这两个数组操作接口,由于不理解, 往往被误用, 或者不知道如何使用.本文尝试给出容易理解的阐述. 数组 什么是数组? 数组是一个基本的数据结构, 是一个在内存中依照线性方式组织元素的方式, ...

  3. [Javascript] Use a custom sort function on an Array in Javascript

    Sorting in Javascript with sort uses lexical sorting by default, which means it will sort in alphabe ...

  4. Array.prototype.forEach()&&Array.prototype.map()

    https://developer.mozilla.org/zh-CN/docs/Web/JavaScript/Reference/Global_Objects/Array/forEach https ...

  5. Function.prototype.bind接口浅析

    本文大部分内容翻译自 MDN内容, 翻译内容经过自己的理解. https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Glo ...

  6. 《Javascript高级程序设计》读书笔记之bind函数详解

    为什么需要bind var name = "The Window"; var object = { name: "My Object", getNameFunc ...

  7. 聊聊Function的bind()

    bind顾名思义,绑定. bind()方法会创建一个新函数,当这个新函数被调用时,它的this值是传递给bind()的第一个参数,它的参数是bind()的其他参数和其原本的参数. 上面这个定义最后一句 ...

  8. JavaScript的Array.prototype.filter()详解

    摘抄与:https://developer.mozilla.org/zh-CN/docs/Web/JavaScript/Reference/Global_Objects/Array/filter 概述 ...

  9. javascript some()函数用法详解

    参数说明callback: 要对每个数组元素执行的回调函数.thisObject : 在执行回调函数时定义的this对象. 功能说明对数组中的每个元素都执行一次指定的函数(callback),直到此函 ...

随机推荐

  1. minio-对象存储

    1. 简介 官方地址 MinIO 是一个基于Apache License v2.0开源协议的对象存储服务.它兼容亚马逊S3云存储服务接口,非常适合于存储大容量非结构化的数据,例如图片.视频.日志文件. ...

  2. 【网络编程】TCPIP-8-套接字的多种选项

    目录 前言 8. 套接字的多种选项 8.1 API getsockopt(); & setsockopt(); 8.2 套接字选项 8.3 缓冲区相关可选项 8.4 端口复用 8.4.1 ti ...

  3. NOIP 模拟 $30\; \rm 毛一琛$

    题解 \(by\;zj\varphi\) 如何判断一个集合可以被拆成两个相等的部分? 枚举两个集合,如果它们的和相等,那么他们的并集就是合法的,复杂度 \(\mathcal O\rm(3^n)\) \ ...

  4. node 报错 throw er; // Unhandled 'error' event 解决办法

    node 报错 Starting child process with 'node web.js' events.js:183 throw er; // Unhandled 'error' event ...

  5. 关于yii2学习笔记:gii的使用

    yii2中的gii无疑是非常强大的代码生成工具,以下是我学习使用gii的一些技巧,跟大家分享一下. 以User为例,在数据库中,创建user表. /*Navicat MySQL Data Transf ...

  6. 简单介绍无限轮播图,js源代码

    无限轮播图js源代码,今天介绍一下用js简单的编写无限轮播图 <!DOCTYPE html> <html>   <head>     <meta charse ...

  7. Bing每日壁纸的RESTful接口实现

    0x00 存在意义 权且当作Docker打包的练习. 显然可以通过构造请求获得每天的壁纸,但是如果想要优雅地在其它地方使用这一网络资源,封装一个RESTful API将会保证整洁美观,在编写CSS等场 ...

  8. AI 常见术语总结

      BN(Batch-normalization)在一层的输出上计算所有特征映射的均值和标准差,并且使用这些值规范化它们的响应.因此使得所有神经图(neural maps)在同样范围有响应,而且是零均 ...

  9. js在不同页面的导航背景不同 (设置网站公共头的导航)

    <script type="text/javascript" src="js/jquery.min.js"></script> < ...

  10. vue js 手写 正则判断 手机号码 和 密码

    const phoneOrEmails = /^1[3|4|5|6|7|8|9][0-9]\d{8}$/             if(this.ruleForms.phoneOrEmail  ==  ...