Saturday, December 10, 2022

the this keyword of JS

the this keyword of JS
class Polygon {
  constructor() {
    this.name = 'Polygon';
  }
}

const poly1 = new Polygon();

console.log(poly1.name); //Polygon


function outer_func()
{
    function inner_func()
    {
        this.prop01 = "value of prop01";
    }
    inner_func();
}

outer_func()

console.log( "prop01=" + prop01 )//value of prop01

var prop02 = "value of prop02";
console.log( "prop02=" + this.prop02 )//value of prop02

outer_func.inner_func2 = function (){
    this.prop03 = "value of prop03";
}
outer_func.inner_func2();
console.log( "prop03=" + outer_func.prop03 )//value of prop03

No comments:

Post a Comment