Skip to content

Instantly share code, notes, and snippets.

@scr2em
Last active August 9, 2023 18:35
Show Gist options
  • Save scr2em/3e56d5214b99976b8de4eb0421b6a73b to your computer and use it in GitHub Desktop.
Save scr2em/3e56d5214b99976b8de4eb0421b6a73b to your computer and use it in GitHub Desktop.
JS Lab 3 - ASAT 2023
function checkThis() {
return this;
}
console.log(checkThis()); // ?
// ---------------------------------------
var obj = {
prop: "hello",
getProp: function() {
return this.prop;
}
};
console.log(obj.getProp()); // ?
// ---------------------------------------
function myFunc() {
return this.a;
}
var obj = {
a: 'obj-a',
myFunc: myFunc
};
const a = 'global-a'; // ES6 <<<< GOOGLE IT
console.log(myFunc()); // ?
// ---------------------------------------
var obj1 = {
name: "obj1",
print: function() {
console.log(this.name);
}
};
var obj2 = { name: "obj2" };
obj2.print = obj1.print;
obj2.print(); // ?
// ---------------------------------------
function outer() {
var inner = () => {
console.log(this); // ES6 <<<< GOOGLE IT
}
inner();
}
outer.call("Hello"); // ?
// ---------------------------------------
var obj = {
a: 1,
getA: function() {
return function() {
return this.a;
}
}
};
var retrieveA = obj.getA();
console.log(retrieveA()); // ?
// ---------------------------------------
var cat = {
sound: "meow",
speak: function() {
return this.sound;
}
};
var dog = {
sound: "woof"
};
console.log(cat.speak.call(dog)); // ?
// ---------------------------------------
var car = {
brand: "Toyota",
getBrand: function() {
return this.brand;
}
};
var getCarBrand = car.getBrand;
console.log(getCarBrand()); // ?
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment