function Hard(str){     var that = {};     that.__proto__ = arguments.callee.prototype ;     that.str = "I am " + str;     setTimeout(that.settime.bind(that));     return that; } Hard.prototype.yanchi = function(m){     console.log("sleep")     var d = new Date();     var n = this._restFirst*1000;     for(var i = 0; i < d; i++){         if( new Date() - d > n ){             console.log("sleep end")             return false;         }     } } Hard.prototype.learn = function( sr ) {     this._learn = sr;     return this; } Hard.prototype.rest = function( num ){     this._rest = num;     return this; } Hard.prototype.restFirst = function ( n ) {     this._restFirst = n;     this._rest = 0;     return this; } Hard.prototype.settime = function(){     var { str, _learn, _rest, _restFirst} = this;     var num = _rest || _restFirst;     if( _restFirst !== undefined ){         this.yanchi();     }else{         console.log(str);     }     if(num){         setTimeout(function(){             console.log( `Start learning after ${ num } seconds` );             if( _restFirst !== undefined ){                 console.log(str);             }             if( _learn ){                 console.log( "Learning " + _learn )             }         },_rest*1000)     } }
1 2

相关推荐

牛客网
牛客企业服务