* 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. [数据库系列之MySQL] Mysql整体架构浅析一

    一.引言 平时我们在做Java系统时,一般情况下都会连接到一个MySQL数据库上去,执行各种增删改查的语句.大部分的Java工程师对MySQL的了解和掌握程度,大致就停留在这么一个阶段:对MySQL可 ...

  2. Git(12)-- Git 分支 - 分支简介

    @ 目录 1.分支简介 1.1.初始化并首次提交 首次提交对象及其树结构: git 的 cat-file 的命令用法: 1.2.修改并第二次提交 第二次提交对象及其树结构: 1.3.修改并第三次提交 ...

  3. OSI网络参考模型学习

    文章目录 一.计算机与网络的发展 1.1 批处理系统 1.2 分时系统 1.3 计算机之间的通信 1.4 基于分组交换技术的计算机网络 1.5 互联网时代的计算机网络 1.6 计算机网络中协议的规定 ...

  4. SpringBoot和mybatis整合报错:Caused by: org.apache.ibatis.builder.BuilderException: Error creating document instance. Cause: org.xml.sax.SAXParseException; lineNumber: 152; columnNumber: 10; 元素类型为 "mapper"

    很明显,报错是xml有问题,于是去检查,发现: 由于粗心,保存的时候,按的太频繁,多按了个s在里面,导致启动报错!

  5. axios 请求数据跳转页面报'$router' of undefined问题

    代码: this.$axios.post("/auth", { 'username': this.username, 'password': this.password }).th ...

  6. uwp 动画之圆的放大与缩小

    xml code --------------------------------------------------- <Page x:Class="MyApp.MainPage&q ...

  7. Flink中的算子操作

    一.Connect DataStream,DataStream ->  ConnectedStream,连接两个保持他们类型的数据流,两个数据流被Connect之后,只是被放在了同一个流中,内部 ...

  8. Go并发控制--Channel篇

    目录 1. 前言 2. 使用channel控制子协程 2.1 使用场景 2.2 总结 1. 前言 我们考虑这么一种场景,协程A执行过程中需要创建子协程A1.A2.A3-An,协程A创建完子协程后就等待 ...

  9. Spring Cloud总结

    restTemplate 消费者模块编写restTemplate配置类,即可在控制层调用提供者模块 // 配置类 @Configuration public class ApplicationCont ...

  10. Linux基础——安装以及常用命令

    Linux基础--常用命令 1.安装Vmware 进入VMware官网:  https://www.vmware.com/cn.html下载安装 镜像推荐网址下载:https://www.linux. ...