Skip to content

Instantly share code, notes, and snippets.

View flavioribeirojr's full-sized avatar
:shipit:
debugging...

Flávio Ribeiro flavioribeirojr

:shipit:
debugging...
View GitHub Profile
class Cart {
constructor() {
this.cart = []
}
onItemAddedToCart() {
alert(`The cart has ${this.cart.length} items`)
}
addItemToCart(item) {
class Cart {
constructor() {
this.cart = []
}
onItemAddedToCart() {
alert(`The cart has ${this.cart.length} items`)
}
addItemToCart(item) {
function createDriver(name) {
return {
drive: function () {
console.log(`${name} is driving...`)
}
}
}
var vanDriver = createDriver('Rogerinho')
function Driver(name) {
this.name = name
}
Driver.prototype.drive = function () {
console.log(`${this.name} is driving...`)
}
var vanDriver = new Driver('Rogerinho')
function Rectangle(width, height) {
this.width = width
this.height = height
}
var rectangle = new Rectangle(30, 10)
console.log(rectangle.width, rectangle.height) // 30 10
function stopMotorFunctions() {
console.log(this.command);
}
var host = {
command: 'Stop motor functions'
}
stopMotorFunctions.call(host) // Stop motor functions
var dog = {
name: 'Pluto',
latido: 'Au',
latir: function () {
console.log(new Array(3).fill(this.latido).join(' '))
}
}
dog.latir() // Au Au Au
function sayMyName() {
console.log(this.name)
}
var name = 'Heisenberg'
sayMyName() // Heisenberg
@flavioribeirojr
flavioribeirojr / this-is-js.array-sum.js
Last active December 30, 2018 16:25
A simple demonstration of
console.log(typeof ([] + [])) // string
@flavioribeirojr
flavioribeirojr / Form.js
Last active October 30, 2018 13:51
Exemplo fluxo pai > filho de formulário
import React, { Component } from 'react'
import ReactDOM from "react-dom";
class Input extends Component {
render() {
return (
<div>
<h2>Filho: {this.props.value}</h2>
<input
name={this.props.name}