startit/eloquentjavascript/06_Objects/obj.js

44 lines
1.1 KiB
JavaScript
Raw Permalink Normal View History

2024-10-24 11:27:53 +02:00
let empty = {};
console.log(Object.getPrototypeOf({}) == Object.prototype);
console.log(Object.getPrototypeOf(Object.prototype));
2024-09-30 11:18:07 +02:00
2024-10-24 11:27:53 +02:00
console.log(Object.getPrototypeOf(Math.max) == Function.prototype);
2024-09-30 11:18:07 +02:00
2024-10-24 11:27:53 +02:00
let protoRabbit = {
speak(line) {
console.log(`The ${this.type} rabbit says '${line}`)
}
2024-09-30 11:18:07 +02:00
};
2024-10-24 11:27:53 +02:00
let blackRabbit = Object.create(protoRabbit);
blackRabbit.type = "black";
blackRabbit.speak("I am fear and darkness");
2024-10-01 13:08:44 +02:00
2024-10-24 11:27:53 +02:00
function makeRabbit(type){
let rabbit = Object.create(protoRabbit);
rabbit.type = type;
return rabbit;
}
class Rabbit {
constructor(type) {
this.type = type;
}
speak(line){
console.log(`The ${this.type} rabbit says '${line}`)
}
}
let killerRabbit = new Rabbit("killer");
const materials = ['Hydrogen', 'Helium', 'Lithium', 'Beryllium']
console.log(materials.map((material) => material.includes('Helium')));
let addABPlussHundred = (a,b) => a + b + 100;
console.log(addABPlussHundred(10,19))
2024-10-04 10:29:31 +02:00
2024-10-24 11:27:53 +02:00
const greetings = name => {
console.log(`Hello, ${name}!`);
}
greetings('Geir');
2024-10-04 10:29:31 +02:00
2024-10-24 11:27:53 +02:00
const myFunction = (param1,param2) => {
2024-10-04 10:29:31 +02:00
2024-10-24 11:27:53 +02:00
}