// http://dmitry.baranovskiy.com/post/91403200
//## 1
if (!("a" in window)) {
var a = 1;
}
alert(a);
This file contains hidden or 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 fun1() { | |
| var a = 1; | |
| return function() { | |
| return a++; | |
| }; | |
| } | |
| var add1 = fun1(); | |
| console.log(add1()); |
This file contains hidden or 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 User = { | |
| count: 1, | |
| getCount: function() { | |
| return this.count; | |
| } | |
| }; | |
| console.log(User.getCount()); |
This file contains hidden or 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 Foo() {} | |
| // Foo.prototype 是Object的一个实例 | |
| console.log(Foo.prototype.__proto__ === Object.prototype); | |
| console.log(Foo.prototype.constructor === Foo); | |
| var f1 = new Foo(); | |
| // f1是Foo的一个实例 | |
| console.log(f1.__proto__ == Foo.prototype); | |
| console.log(f1.__proto__.constructor === Foo); |
This file contains hidden or 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
| Rank | Repository | Language | Stars | |
|---|---|---|---|---|
| 1 | twbs/bootstrap | JavaScript | 62111 | |
| 2 | jquery/jquery | JavaScript | 27082 | |
| 3 | joyent/node | JavaScript | 26352 | |
| 4 | h5bp/html5-boilerplate | CSS | 23355 | |
| 5 | mbostock/d3 | JavaScript | 20715 | |
| 6 | rails/rails | Ruby | 20284 | |
| 7 | FortAwesome/Font-Awesome | CSS | 19506 | |
| 8 | bartaz/impress.js | JavaScript | 18637 | |
| 9 | angular/angular.js | JavaScript | 17994 |
This file contains hidden or 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 copy(obj) { | |
| // if (Object.prototype.toString.call(obj) !== '[object Object]') { | |
| if (typeof obj !== 'object') { | |
| return; | |
| } | |
| var ret = obj.constructor === Object ? {} : []; | |
| for (var i in obj) { | |
| if (obj[i].constructor === Array) { | |
| ret[i] = Array.prototype.slice.call(obj[i]); |
This file contains hidden or 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
| <!DOCTYPE html> | |
| <html lang="en"> | |
| <head> | |
| <meta charset="UTF-8"> | |
| <title></title> | |
| <style type="text/css" media="all"> | |
| #a {display: block;width: 200px; margin: 10px;border: 1px solid #f00;} | |
| #span {display:block; width: 100px; margin: 20px; border: 1px solid #0f0;} | |
| </style> | |
| </head> |
This file contains hidden or 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
| a = _.reduce($("tr"), function(memo, v, i) { | |
| var $el = $(v); | |
| var obj = {}; | |
| obj.id = $.trim($el.find('.end').text()); | |
| obj.date = $el.find('td').eq(1).text(); | |
| obj.red = $el.find('.STYLE13').html() && $el.find('.STYLE13').html().replace(/ /g, ' '); | |
| obj.blue = $el.find('.STYLE12').text(); | |
| if (obj.id !== '') { | |
| memo.push(obj); | |
| } |
This file contains hidden or 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 fs = require('fs'); | |
| var http = require('http'); | |
| http.get('http://img31.mtime.cn/CMS/Gallery/2014/01/01/162652.23483887_160X160.jpg', function(res) { | |
| console.log("Got response: " + res.statusCode); | |
| var fw = fs.createWriteStream('./img2.jpg', {flags: 'w', encoding: 'binary', mode: '0666'}); | |
| res.pipe(fw); | |
| }).on('error', function(e) { | |
| console.log("Got error: " + e.message); | |
| }); |