xgqfrms™, xgqfrms® : xgqfrms's offical website of GitHub!

console.log & front-end jobs

bind & function

let log = console.log;
let obj = {};

log(obj);
log(typeof Function.prototype.bind);
log(typeof Function.prototype.bind()); 
log(Function.prototype.bind.name);
log(Function.prototype.bind().name); 
//{}
//function
//function
//bind
//bound 


Function.prototype;
//ƒ () { [native code] }
Function.prototype.bind;
//ƒ bind() { [native code] }
Function.prototype.bind();
//ƒ () { [native code] }
Function.prototype.bind.name;
//"bind"
Function.prototype.bind().name;
// "bound "

https://zhuanlan.zhihu.com/p/50539121

vanilla js customize bind this

"use strict";

/**
 *
 * @author xgqfrms
 * @license MIT
 * @copyright xgqfrms
 * @created 2019-08-31
 * @modified
 *
 * @description vanilla js customize bind this
 * @augments
 * @example
 * @link
 *
 */

let log = console.log;

let obj = {
    x: 42,
    getX: function() {
        log(`this =`, this);
        log(`obj.x =`, obj.x);
        return this.x;
    }
};

// The function gets invoked at the global scope
let unboundGetX = obj.getX;
// log(unboundGetX());
// undefined

let boundGetX = unboundGetX.bind(obj);
// log(boundGetX());
// 42

Function.prototype.customizeBind = function() {
    let func = this;
    let _this = arguments[0];
    // arguments is array-like, not an array!
    // let args = Array.prototype.slice.apply(arguments,[1]);
    let args = [...arguments].slice(1);
    // log(`func =`, func);
    // log(`_this =`, _this);
    // log(`args =`, args);
    if (typeof func === "function") {
        return function() {
            let allArgs = args.concat([...arguments].slice(0));
            // log(`allArgs =`, allArgs);
            return func.apply(_this, allArgs);
        };
    } else {
        throw new Error(`Function.prototype.customizeBind - what is you trying to be bound is not callable!`);
    }
};


let customizeBoundGetX = unboundGetX.customizeBind(obj);
log(customizeBoundGetX());



ASCII text art


console.log(`%c
                                  _____                   _______                   _____                    _____                    _____                    _____
        ______                   /                     /::                     /                      /                      /                      /    
       |::|   |                 /::                   /::::                   /::                    /::                    /::\____                /::    
       |::|   |                /::::                 /::::::                 /::::                  /::::                  /::::|   |               /::::    
       |::|   |               /::::::               /::::::::               /::::::                /::::::                /:::::|   |              /::::::    
       |::|   |              /:::/:::             /:::/~~:::             /:::/:::              /:::/:::              /::::::|   |             /:::/:::    
       |::|   |             /:::/  :::           /:::/    :::           /:::/__:::            /:::/__:::            /:::/|::|   |            /:::/__:::    
       |::|   |            /:::/    :::         /:::/    / :::         /::::   :::          /::::   :::          /:::/ |::|   |            :::   :::    
       |::|   |           /:::/    / :::       /:::/____/   :::\____   /::::::   :::        /::::::   :::        /:::/  |::|___|______    ___:::   :::    
 ______|::|___|___ ____  /:::/    /   ::: ___ |:::|    |     |:::|    | /:::/:::   :::      /:::/:::   :::\____  /:::/   |::::::::      /   :::   :::    
|:::::::::::::::::|    |/:::/____/  ___:::|    ||:::|____|     |:::|____|/:::/  :::   :::\____/:::/  :::   :::|    |/:::/    |:::::::::\____/::   :::   :::\____
|:::::::::::::::::|____|:::     /  /:::|____| :::   _\___/:::/    / ::/    :::   ::/    /::/   |::::  /:::|____|::/    / ~~~~~/:::/    /:::   :::   ::/    /
 ~~~~~~|::|~~~|~~~       :::    /:: ::/    /   ::: |::| /:::/    /   /____/ :::   /____/  /____|:::::/:::/    /  /____/      /:::/    /  :::   :::   /____/
       |::|   |           :::   ::: /____/     :::|::|/:::/    /             :::                |:::::::::/    /               /:::/    /    :::   :::    
       |::|   |            :::   :::\____        ::::::::::/    /               :::\____           |::|::::/    /               /:::/    /      :::   :::\____
       |::|   |             :::  /:::/    /         ::::::::/    /                 ::/    /           |::| ::/____/               /:::/    /        :::  /:::/    /
       |::|   |              :::/:::/    /           ::::::/    /                   /____/            |::|  ~|                    /:::/    /          :::/:::/    /
       |::|   |               ::::::/    /             ::::/____/                                       |::|   |                   /:::/    /            ::::::/    /
       |::|   |                ::::/    /               |::|    |                                        ::|   |                  /:::/    /              ::::/    /
       |::|___|                 ::/____/                |::|____|                                         :|   |                  ::/    /                ::/    /
        ~~                                                ~~                                                |___|                   /____/                  /____/
                                                                                                                                                                              
`, `color: #0f0; background: #000;`);

http://patorjk.com/software/taag/#p=display&h=0&v=0&f=Alpha&t=xgqfrms

refs

http://www.alloyteam.com/2020/01/14184/#prettyPhoto

    //Alloyteam 招聘广告
    window.console && console.log && console.log("
"+"   _    _  _                _____                         
  /_\  | || |  ___   _   _ /__   \  ___   __ _  _ __ ___  
 //_\\ | || | / _ \ | | | |  / /\/ / _ \ / _` || '_ ` _ \ 
/  _  \| || || (_) || |_| | / /   |  __/| (_| || | | | | |
\_/ \_/|_||_| \___/  \__, | \/     \___| \__,_||_| |_| |_|
                     |___/

 欢迎加入AlloyTeam:请将简历(邮件标题后面再加上'from console')发送至 %c Kinvix@QQ.com 
", "color:red");


Flag Counter

©xgqfrms 2012-2020

www.cnblogs.com 发布文章使用:只允许注册用户才可以访问!


原文地址:https://www.cnblogs.com/xgqfrms/p/11442730.html