<commit_before><!DOCTYPE html>
<html>
<head lang="en">
    <meta charset="UTF-8">
    <title></title>
    <script>
        /*
         * bind的核心是bind之后返回的是一个function
         * mdn给出的答案
         * */
        Function.prototype.bind = function (oThis) {
            if (typeof this !== "function") {
                // closest thing possible to the ECMAScript 5
                // internal IsCallable function
                throw new TypeError("Function.prototype.bind - what is trying to be bound is not callable");
            }
            var aArgs = Array.prototype.slice.call(arguments, 1);

            var fToBind = this;//要调用的function

            var fNOP = function () {
            };

            var fBound = function () {
                return fToBind.apply(this instanceof fNOP
                                ? this
                                : oThis || this,
                        aArgs.concat(Array.prototype.slice.call(arguments)));
            };

            fNOP.prototype = this.prototype;

            fBound.prototype = new fNOP();

            return fBound;
        };

        /*//我的实现方式
        Function.prototype.bind = function(obj){
            //obj是传递过来的ctx环境
            if(typeof this !== 'function'){
                //防止采用call的方式调用bind
                throw new Error();
            }
            var fn = this;

            //如何获取this的参数？
            return function(){
                console.log(this);
                //这里获取arguments
                fn.apply(obj || this,arguments);
            }
        };
*/

        function A(a) {
            this.a = a;
        }
        A.prototype.say = function () {
            console.log('hello world');
        };

        var obj = new A(2);
        obj.b = 3;


        (function (b) {
            //调用bind的核心需要 同时能够调用obj的prototype上面的函数与属性
            console.log(this.a);
            console.log(this.b);
            console.log(b);
            console.log(this.say);
        }).bind(obj)(10);



    </script>
</head>
<body>

</body>
</html><commit_msg>fixed no return bind function<commit_after><!DOCTYPE html>
<html>
<head lang="en">
    <meta charset="UTF-8">
    <title></title>
    <script>
        /*
         * bind的核心是bind之后返回的是一个function
         * mdn给出的答案
         * */
        Function.prototype.bind = function (oThis) {
            if (typeof this !== "function") {
                // closest thing possible to the ECMAScript 5
                // internal IsCallable function
                throw new TypeError("Function.prototype.bind - what is trying to be bound is not callable");
            }
            var aArgs = Array.prototype.slice.call(arguments, 1);

            var fToBind = this;//要调用的function

            var fNOP = function () {
            };

            var fBound = function () {
                return fToBind.apply(this instanceof fNOP
                                ? this
                                : oThis || this,
                        aArgs.concat(Array.prototype.slice.call(arguments)));
            };

            fNOP.prototype = this.prototype;

            fBound.prototype = new fNOP();

            return fBound;
        };

        /*//我的实现方式
        Function.prototype.bind = function(obj){
            //obj是传递过来的ctx环境
            if(typeof this !== 'function'){
                //防止采用call的方式调用bind
                throw new Error();
            }
            var fn = this;

            //如何获取this的参数？ 保持返回值！！
            return function(){
                console.log(this);
                //这里获取arguments
                return fn.apply(obj || this,arguments);
            }
        };
*/

        function A(a) {
            this.a = a;
        }
        A.prototype.say = function () {
            console.log('hello world');
        };

        var obj = new A(2);
        obj.b = 3;


        (function (b) {
            //调用bind的核心需要 同时能够调用obj的prototype上面的函数与属性
            //还有就是函数的返回值需要确保。
            console.log(this.a);
            console.log(this.b);
            console.log(b);
            console.log(this.say);
        }).bind(obj)(10);



    </script>
</head>
<body>

</body>
</html>
{'fraction_non_alphanumeric': 0.11622334052240595, 'fraction_numerical': 0.0033549005511622335, 'mean_word_length': 1.224946695095949, 'pattern_counts': {'":': 0, '<': 27, '<?xml version=': 0, '>': 27, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4507840', 'n_tokens_mistral': 1251, 'n_tokens_neox': 1236, 'n_words': 240}