bind 以及原型 1px边框的实现(面试后内容整理)

一、bind函数返回的是一个function 函数
因此对bind函数扩展能够是:

 Function.prototype.mybind = function mybind (context) {
       var _this = this;
       var outArg = Array.prototype.slice.call(arguments,1);
       // 兼容状况下
       if('bind' in Function.prototype) {
           return this.bind.apply(this,[context].concat(outArg));
       }
       // 不兼容状况下
       return function () {
           var inArg = Array.prototype.slice.call(arguments,0);
           inArg.length === 0?inArg[inArg.length]=window.event:null;
           var arg = outArg.concat(inArg);
           _this.apply(context,arg);
       }
   }
    function bbb(){
       console.log(this.aaa);
    }
   bbb.bind(o)()

 

 

二、理解原型,构造函数,实例css

以下图:git

 

 

Range函数:github

   
//构造函数
function Range(to,from){ this.from=from; this.to=to; console.log(this
); }
// Range的原型 Range.prototype
={ include:function(x){return this.from<=x&&x<=this.to}, foreach:function(f){ for (var x=Math.ceil(this.from);x<=this.to;x++){ f(x); } }, toString:function(){ return "("+this.from+"..."+this.to+")"; } }
//实例
var b=new Range(1,3);

  

构造函数的this是 Object正则表达式

 

题目是这样的有道笔试题;查找a在b字符串的位置,app

例如:'aaa'   'bbbaaa'  返回3函数

这道题仍是挺有意思当时我想到的是使用正则表达式;经过match来的到 结果取到index就能够了;可是注意还要考虑正则的特殊字符的特殊处理; this

 

 

1px边框的实现:spa

https://jinlong.github.io/2015/05/24/css-retina-hairlines/   (mark)prototype

相关文章
相关标签/搜索