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 person = { | |
_name: 'John Doe', | |
getSecretIdentity: function (){ | |
return this._name; | |
} | |
}; | |
var stoleSecretIdentity = person.getSecretIdentity; | |
console.log(stoleSecretIdentity()); |
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 myObject = { | |
foo: "bar", | |
func: function() { | |
var self = this; | |
console.log("outer func: this.foo = " + this.foo); | |
console.log("outer func: self.foo = " + self.foo); | |
(function() { | |
console.log("inner func: this.foo = " + this.foo); | |
console.log("inner func: self.foo = " + self.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
var age = 20 | |
(function () { | |
console.log("Original age is " + age) | |
var age = 30 | |
console.log("The new age is " + age) | |
})() |
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 foo = function(){ | |
// Some code | |
}; | |
function bar(){ | |
// Some code | |
}; |
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 a = [0,1,2,3,4,5,6,7,8,9] | |
a.slice() | |
a.splice() | |
a.concat([24]) | |
a.reverse() |
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
const operations = [] | |
for (var i = 0; i < 5; i++) { | |
operations.push(() => { | |
console.log(i) | |
}) | |
} | |
for (const operation of operations) { | |
operation() |
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
const multiply = x => y => z => x * y * z | |
console.log( multiply(2)(3)(4) ) |
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
#!/usr/bin/env ruby | |
require 'socket' | |
client = TCPSocket.open("127.0.0.1", 2222) {|s| s.send("hello", 0) } |
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
#!/usr/bin/env ruby | |
require 'open-uri' | |
open('http://www.imdb.com/title/tt0421054/') do |f| | |
f.read.match(/User Rating:<\/b>\s*([\d\.]+\/[\d\.]+)<\/b>/) | |
puts $1 | |
end |
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
class Array | |
def my_map | |
result = [] | |
each do |e| | |
result << (yield e) | |
end | |
result | |
end | |
end |
NewerOlder