zoukankan      html  css  js  c++  java
  • 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 发布文章使用:只允许注册用户才可以访问!


  • 相关阅读:
    深入理解Spring Redis的使用 (三)、使用RedisTemplate的操作类访问Redis
    深入理解Spring Redis的使用 (二)、RedisTemplate事务支持、序列化
    Elasticsearch 评分score计算中的Boost 和 queryNorm
    Docker 镜像构建的时候,应该小心的坑
    怎么给kibana加上权限?
    网站异常了,日志要怎么看?
    使用 Gradle 配置java项目
    Cassandra 类型转换限制
    Elasticsearch 排序插件的开发
    ElasticSearch 2.0以后的改动导致旧的资料和书籍需要订正的部分
  • 原文地址:https://www.cnblogs.com/xgqfrms/p/11442730.html
Copyright © 2011-2022 走看看