Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // SCOPE / HOISTING
- function something() {
- for (var i = 0; i< 10; i++) {
- //console.log('before' + text);
- var text = 'Hello ' + i;
- //text = 'x';
- console.log(text);
- }
- //console.log('Outside: ' + text);
- }
- // CLOSURES
- function test () {
- let counter = 0;
- return function inc() {
- counter++;
- console.log(counter);
- }
- }
- // this
- let obj = {
- x: 'hello',
- m: function () {
- console.log(this.x);
- }
- }
- let obj2 = {x: 'yo'};
- function Constr() {
- this.x = 'hello';
- this.m = () => {
- console.log(this.x);
- };
- }
- let obj3 = new Constr();
- function context() {
- obj.m();
- // let f = obj.m;
- // let f = obj.m.bind(obj);
- // f();
- // obj.m.call(obj2);
- // setTimeout(obj.m, 700);
- }
- // PROTOTYPE
- function Car() {
- this.wheels = 4;
- }
- function proto() {
- console.log(Car.prototype.constructor === Car);
- }
- function Person(name) {
- this.name = name;
- }
- Person.prototype.sayMyName = function () {
- console.log(this.name);
- }
- function BadPerson(name) {
- this.name = name;
- }
- BadPerson.prototype = Object.create(Person.prototype);
- BadPerson.prototype.steal = function () {console.log('stole something')};
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement