[ Launch: test ] cc4d8c949af613fdee4e by karenpeng[ Launch: test ] 4653053 by enjalot[ Launch: test ] 4652017 by enjalot[ Launch: test ] 4582399 by enjalot
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function Robot(){ | |
this.inside = [] | |
this.a = 0 | |
} | |
Robot.prototype.outside = [] | |
Robot.prototype.b = 0 | |
Robot.prototype.test = function(){ | |
console.log(this.b) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function Parent () { | |
this.arrayInside = [1]; | |
this.numberInside = 1; | |
} | |
Parent.arrayOutside = [2]; | |
Parent.numberOutside = 2; | |
Parent.prototype.arrayPrototype = [3]; | |
Parent.prototype.numberPrototype = 3; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// class A | |
function ParentA(a) { | |
this.a = a; | |
}; | |
ParentA.prototype.displayA = function () { | |
console.log('a: %s', this.a); | |
} | |
// class B | |
function ParentB(b) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function block(){ | |
var lock = false | |
return function dosomething(){ | |
if(!lock){ | |
console.log('coo') | |
lock = true | |
} | |
setTimeout(function(){ | |
lock = false |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var flattenObject = function(ob) { | |
var toReturn = {}; | |
for (var i in ob) { | |
if (!ob.hasOwnProperty(i)) continue; | |
if ((typeof ob[i]) == 'object') { | |
var flatObject = flattenObject(ob[i]); | |
for (var x in flatObject) { | |
if (!flatObject.hasOwnProperty(x)) continue; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var Mocha = require('mocha'); | |
var assert = require('assert'); | |
var mocha = new Mocha({ui: 'bdd'}); | |
/* | |
Your previous Plain Text content is preserved below: | |
// 实现一个函数 sequence,参数是一个数组,是一系列的异步函数,返回一个新的函数,这个新的函数在调用的时候,会顺序的执行之前传递给 sequence 的函数数组,前一个函数的返回值作为下一个函数的参数,新函数的参数前面部分会传递给函数数组的第一个函数,当全部执行完成后,调用 新函数的 callback。 | |
sequence([add1, add2])(1, function (err, res) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function parallel(arrOfFunc, maxNum, callback){ | |
var len = arrOfFunc.length | |
var result = [] | |
// 最好是增加一个标记 | |
var done = false | |
var lastIndex = maxNum -1 | |
for(var i = 0; i < maxNum; i++){ | |
// wrap 为什么要返回一个函数然后执行?直接在 wrap 里面执行就可以了 | |
wrap(i, arrOfFunc[i]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function iterator(arr){ | |
var id = setInterval( | |
function(){ | |
console.log('haha') | |
if(arr.length > 0){ | |
console.log(arr.shift()) | |
}else{ | |
clearInterval(id) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
for(var i = 0; i < 5; i++){ | |
setTimeout(function(){ | |
//console.log(i) | |
}, i * 1000) | |
} | |
for(var i = 0; i < 5; i++){ | |
(function(i){ | |
setTimeout(function(){ | |
console.log(i) |