Skip to content

Instantly share code, notes, and snippets.

View radzionc's full-sized avatar

Radzion Chachura radzionc

View GitHub Profile
@radzionc
radzionc / const.js
Last active August 18, 2017 20:38
JS developer in few minutes
const dog = {
age: 4,
name: 'Ronni'
}
dog.age = 6 // OK
dog = {} // ERROR
function standard() {
return 'Rock'
}
const arrowLike = () => 'Rock'
const dog = {
name: 'Ronni',
age: 4,
talk: function() {
retun `my name is ${this.name}`
}
}
// if you have some variables around
const name = 'Ronni'
const data = fetch('http://something.com')
.then(result => result.json())
const Dog = (age, name) => ({
age,
name,
talk: function() {
...
}
})
const procesData = ({ someProp, otherProp }) => {
...
}
cosnt one = {
a: 1,
b: 2
}
const two = {
c: 2,
d: 3
}
@radzionc
radzionc / vector1.js
Last active September 10, 2017 10:40
const create = (proto, props) =>
Object.assign(Object.create(proto), props)
const Vector2D = (x, y) => create({
}, {
x,
y,
length: Math.hypot(x, y)
}
)
...
scaleBy (factor) {
return Vector2D(x * factor, y * factor)
},
negate () {
return this.scaleBy(-1)
},
normalize () {
return this.scaleBy(1 / this.length)
}
...
add ({ x, y }) {
return Vector2D(this.x + x, this.y + y)
},
subtract ({ x, y }) {
return Vector2D(this.x - x, this.y - y)
}
...