Skip to content

Instantly share code, notes, and snippets.

View woliveiras's full-sized avatar
🤖
Always typing code

William Oliveira woliveiras

🤖
Always typing code
View GitHub Profile
function httpGet(url) {
return new Promise((resolve, reject) => {
const request = new XMLHttpRequest();
request.onload = function () {
if (this.status === 200) {
resolve(this.response);
} else {
reject(new Error(this.statusText));
}
function printf(format, …params) {
console.log('params: ', params);
console.log('format: ', format);
}
printf('%s %d %.2f', 'adrian', 321, Math.PI); // params: [“adrian”, 321, 3.141592653589793] && “format: %s %d %.2f”
function printf(format) {
var params = [].slice.call(arguments, 1);
console.log('params: ', params);
console.log('format: ', format);
}
printf('%s %d %.2f', 'adrian', 321, Math.PI); // params: [“adrian”, 321, 3.141592653589793] && “format: %s %d %.2f”
var logArguments = function() {
return arguments;
};
logArguments(1, 2, 3, 4, 5) // > [1, 2, 3, 4, 5]
const numbers = ['1', '2', '3', '4'];
for(const number of numbers) {
console.log(number);
}
function example(x = "The x is the x", y = "The y is the y"){
x = x;
y = y;
console.log(x, y);
}
example(); // “The x is the x” && “The y is the y”
function example(x, y){
x = x || "The x is the x";
y = y || "The y is the y";
console.log(x, y);
}
example(); // “The x is the x” && “The y is the y”
var SUV = (function () {
function SUVConstructor(model){
Car.call(this, model);
}
SUVConstructor.prototype = Object.create(Car.prototype);
SUVConstructor.prototype.constructor = Car;
SUVConstructor.prototype.run = function run() {
Car.prototype.run.call(this);
class SUV extends Car {
run() {
super.run();
console.log(`$And {this.model} climbs up to the mountain`);
}
}
const jeep = new SUV(‘Jeep’);
jeep.run(); // “Jeep is running more faster than The Flash!” && “And Jeep climbs up to the mountain”
brasilia // > Car {model: “Brasilia”, color: null}
// Utilizando o setter
brasilia.color = "Amarela" // “Amarela”
brasilia // > Car {model: “Brasilia”, color: “Amarela”}
// Utiliando o getter
brasilia.color // "Amarela"