Skip to content

Instantly share code, notes, and snippets.

Avatar

moisescastillo

View GitHub Profile
@moisescastillo
moisescastillo / JS_fetch_03.js
Created Aug 16, 2020
Javascript fetch example 03
View JS_fetch_03.js
fetch("https://jsonplaceholder.typicode.com/posts/")
.then(function(response) {
if (response.status !== 200) {
console.log('Error en la respuesta HTTP');
return;
}
return response.json();
})
.then(function(dataJson) {
@moisescastillo
moisescastillo / JS_fetch_02.js
Created Aug 16, 2020
Javascript fetch example 02
View JS_fetch_02.js
fetch("https://jsonplaceholder.typicode.com/posts/")
.then(function(response) {
if (response.ok) {
response.json().then(function(dataJson) {
dataJson.forEach((value, index) => {
console.log(value.id);
console.log(value.title);
console.log(value.body);
console.log(value.userId);
});
@moisescastillo
moisescastillo / JS_fetch_01.js
Created Aug 14, 2020
Javascript fetch example 01
View JS_fetch_01.js
fetch('https://jsonplaceholder.typicode.com/posts/')
.then(
function(response) {
if (response.status !== 200) {
console.log(response.status);
return;
}
response.json().then(function(data) {
data.forEach((value, index) => {
View JS_json_request.js
var requestJSON = 'https://mdn.github.io/learning-area/javascript/oojs/json/superheroes.json';
let request = new XMLHttpRequest();
request.open('GET', requestJSON);
request.responseType = 'json';
request.send();
request.onload = function() {
let data = request.response;
@moisescastillo
moisescastillo / JS_object_prototype.js
Created Jul 19, 2020
Javascript modifying prototypes
View JS_object_prototype.js
function Person(name) {
this.name = name;
this.greeting = function() {
console.log(`Hi I'm ${this.name}`);
}
}
let person1 = new Person('Peter');
let person2 = new person1.constructor('Sarah');
@moisescastillo
moisescastillo / JS_object_constructor.js
Created Jul 19, 2020
Javascript, the constructor property
View JS_object_constructor.js
function Person(name) {
this.name = name;
this.greeting = function() {
console.log(`Hi I'm ${this.name}`);
}
}
let person1 = new Person('Peter');
let person2 = new person1.constructor('Sarah');
@moisescastillo
moisescastillo / JS_object_instance.js
Created Jul 19, 2020
Javascript object instances
View JS_object_instance.js
function Person(name) {
this.name = name;
this.greeting = function() {
console.log(`Hi I'm ${this.name}`);
}
}
let person1 = new Person('Peter');
let person2 = new Person('Sarah');
View JS_object_basic.js
const person = {
name: {first:'Bob', last: 'Smith'},
age: 32,
gender: 'male',
interests: ['Music', 'Boxing'],
greeting: function() {
console.log(`Hi, I\'m ${this.name.first}`);
},
fullName: function() {
console.log(`${this.name.first} ${this.name.last}`);
@moisescastillo
moisescastillo / JS_call.js
Last active Jul 11, 2020
JavaScript Function Call
View JS_call.js
// JavaScript Function Call
let person = {
bio: function() {
return `Name: ${this.name}, Age: ${this.age}`;
}
}
function greeting(message) {
return `${this.name} : ${message}`;
@moisescastillo
moisescastillo / JS_map.js
Last active Jul 11, 2020
JavaScript map method
View JS_map.js
// JS: map() method
let clientes = [
{nombre: "Luis", edad: 22},
{nombre: "Alberto", edad: 31},
{nombre: "Eduardo", edad: 19}
];
let foo = clientes.map(function(cliente) {
return cliente.nombre;