JSFiddle - React, Tailwind, and code Playground

by ancientsion

JavaScript

intervalID = null;
        
        function Scenario(name){
  this.name = name;
  this.ships = [];
  this.ini = function(){
    for (var i = 0; i < this.ships.length; i++){
        this.ships[i].ini();
    }
  }
}


function Ship(name){
  this.name = name;
  this.ini = function(){
      var _this = this;
      intervalID = setInterval(function(){
          console.log(this.name);
      }, 250)      
  }
}


var scenario = new Scenario("scenario");
var ship = new Ship("Ship");


scenario.ships.push(ship);
scenario.ini();