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 Cart { | |
constructor() { | |
this.cart = [] | |
} | |
onItemAddedToCart() { | |
alert(`The cart has ${this.cart.length} items`) | |
} | |
addItemToCart(item) { |
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 Cart { | |
constructor() { | |
this.cart = [] | |
} | |
onItemAddedToCart() { | |
alert(`The cart has ${this.cart.length} items`) | |
} | |
addItemToCart(item) { |
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 createDriver(name) { | |
return { | |
drive: function () { | |
console.log(`${name} is driving...`) | |
} | |
} | |
} | |
var vanDriver = createDriver('Rogerinho') |
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 Driver(name) { | |
this.name = name | |
} | |
Driver.prototype.drive = function () { | |
console.log(`${this.name} is driving...`) | |
} | |
var vanDriver = new Driver('Rogerinho') |
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 Rectangle(width, height) { | |
this.width = width | |
this.height = height | |
} | |
var rectangle = new Rectangle(30, 10) | |
console.log(rectangle.width, rectangle.height) // 30 10 |
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 stopMotorFunctions() { | |
console.log(this.command); | |
} | |
var host = { | |
command: 'Stop motor functions' | |
} | |
stopMotorFunctions.call(host) // Stop motor functions |
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 dog = { | |
name: 'Pluto', | |
latido: 'Au', | |
latir: function () { | |
console.log(new Array(3).fill(this.latido).join(' ')) | |
} | |
} | |
dog.latir() // Au Au Au |
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 sayMyName() { | |
console.log(this.name) | |
} | |
var name = 'Heisenberg' | |
sayMyName() // Heisenberg |
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
console.log(typeof ([] + [])) // string |
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
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} |