Skip to content

Instantly share code, notes, and snippets.

@Arguseye
Created November 6, 2014 04:03
Show Gist options
  • Select an option

  • Save Arguseye/01d30d114ae00ec03449 to your computer and use it in GitHub Desktop.

Select an option

Save Arguseye/01d30d114ae00ec03449 to your computer and use it in GitHub Desktop.
The first commented line is your dabblet’s title
/**
* The first commented line is your dabblet’s title
*/
background: #f06;
background: linear-gradient(45deg, #f06, yellow);
min-height: 100%;
<!-- content to be placed inside <body>…</body> -->
// alert('Hello world!');
Array.prototype.forEach = function(fn, thisArg){
//参数需要判断,throw exception是规范里面写的
if(typeof fn !== "function"){
throw new Error("TypeError exception");
}
var array = this,
length = array.length,//减少作用链的请求,在做数组操作时要考虑到length的自增长
i = 0;
//var a = function() { console.log(this); }; a.call(void 0); void 0 给和不给this的对象都是指向window的,下面这句话是多于
//thisArg = (typeof thisArg === "undefined" ) ? window : thisArg;
for(;i < length;i++){
//var a = []; a[3] = 4; a.hasOwnProperty(1) === false; a.hasOwnProperty(3) === true; 就找第三个这个元素
if(array.hasOwnProperty(i)){
fn.call(thisArg, array[i], i, array);
}
}
}
{"view":"split","fontsize":"100","seethrough":"","prefixfree":"1","page":"javascript"}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment