The instanceof operator does not recognize the value as an instance and is returning false, even though it

Is there a method to verify the current instance being used?

This is what I am logging to the console:

import { OrthographicCamera } from 'three';

// Later in the file:

console.log(camera instanceof OrthographicCamera, camera);

and the result is false, but when I check the value of camera, I see this:

https://i.stack.imgur.com/gDJ9o.png

I'm unsure why it indicates that the camera isn't an instance, so is there a way to gather more information on what it actually represents?

This is where the camera is initialized:

export function Camera(options?: CameraOptions) {
  return function (target: new () => object) {
    return class GameCamera extends target {
      readonly camera!: Camera;  
      constructor() {
        super();
        const dim = this.cameraDimensions();

        // create the Three camera
        this.camera = new OrthographicCamera(dim.left, dim.right, dim.top, dim.bottom, options?.near ?? 0, options?.far ?? 100);
      }
    }
  }
}}

The camera is created within the Decorator and added to the gameObjects array. When I access the activeCamera, it refers to the above decorator extending target.

This is where I perform the instanceof comparison:

@Injectable({ providedIn: 'root' })
export class Camera {
  get activeCamera() {
    return Engine.activeCamera;
  }

  mouseToWorldPoint(mousePoint: Vector3) {
    if (this.activeCamera) {
      // Here is the verification:
      console.log(camera instanceof OrthographicCamera, camera);
    }
  }
}

This is how the camera is retrieved:

export class Engine {
  static gameObjects: GameObject[] = [];
  static get activeCamera() {
    return this.gameObjects.find(i => i.gameObjectType === 'camera' && i.isActive === true) as GameCamera | undefined;
  };
}

I have organized the project into multiple npm workspaces:

{
  "name": "game-engine",
  "version": "1.0.0",
  "scripts": {
    "start": "npm run start --workspace=test"
  },
  "workspaces": [
    "test",
    "packages/core",
    "packages/common",
    "packages/input",
    "packages/objects"
  ]
}

2 of the workspaces depend on modules from the three module.

  • class GameCamera belongs to the packages/objects module (creates the camera).
  • class Camera belongs to the packages/common module (verifies the instance).

Note: This setup has been functioning like this for some time and this issue seems to have recently surfaced.

Answer №1

To resolve the issue at hand, I took the following steps within the packages/core package: I included an export statement to export threejs.

index.ts (@engine/core)

import * as Three from 'three';
export { Three };

Subsequently, whenever I needed to utilize threejs in another package, I simply referenced the core package like so:

@engine/objects/something.ts

import { Three } from '@engine/core';

export class CreateObject {
  constructor(){
    this.obj = new Three.Object3D();
  }
}

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Angular HttpClient mapping causes the removal of getters from the target object

Utilizing the HttpClient to fetch Json data from an API, I am utilizing the autoMapping feature of the HttpClient to map the json response to a specified object in this manner: this.httpClient.post<Person>(url, body, { headers: headers, params: http ...

"Patience is key when waiting for the alert dialog response in Vuetify

I currently have a reusable component called Alert.vue. <v-dialog v-if="alertDict" v-model="alertDict.showDialog" max-width="460"> <v-card> <v-card-title>Title</v-card-title> & ...

Activate continuous speech identification

Is it possible to activate the capability of recognizing continuous speech through the REST API (using javascript SDK) with the Bing Speech API? The Javascript SDK example available at https://github.com/Microsoft/Cognitive-Speech-STT-JavaScript only seem ...

I came across a fascinating finding during my JavaScript studies, but its origin remains a mystery to

I recently wrote some code and was surprised to find that it did not generate any output. Here is the snippet of code: var a1 = undefined; var a2 = 5; if(a1 > a2) alert(1); if(a1 < a2) alert(2); if(a1 >= a2) alert(3); if(a1 <= a2) ...

What is the capability of dynamically generating an index in Typescript?

Can you explain why the Typescript compiler successfully compiles this code snippet? type O = { name: string city: string } function returnString(s: string) { return s } let o1: O = { name: "Marc", city: "Paris", [returnString("random")]: ...

Steps for adjusting the matMenuTriggerFor area so it only triggers when hovering over the arrow

Hello there! I'm currently working on adjusting the trigger area for opening the next menu panel. Right now, the next menu panel opens whenever I hover over either the title or the arrow. However, my goal is to have the menu open only when I hover ove ...

Offering a limited selection of generic type options in TypeScript

Is there a shorthand in TypeScript for specifying only some optional types for generic types? For example, let's say I have a class with optional types: class GenericClass<A extends Type1 = Type1, B extends Type2 = Type2, C extends Type3 = Type3> ...

JavaScript - Not a Number

I am currently facing an issue while attempting to calculate the Markup of a product. I keep receiving a 'NaN' error in my console, which I understand stands for Not a Number. However, I am struggling to identify and rectify the root cause of thi ...

Experiencing problems with the Locale setting when utilizing the formatNumber function in Angular's core functionalities

I am having trouble formatting a number in Angular using the formatNumber function from the Angular documentation. Here is my code snippet: import {formatNumber} from '@angular/common'; var testNumber = 123456.23; var x = formatNumber(Numb ...

What is the process for getting non-event javascript instructions to function properly once a DOM element has been added

After inserting DOM elements (such as an AJAX response), event-delegation is necessary to ensure that events work properly. But what about basic JavaScript instructions? All instructions are organized by affected PHP page to simplify code updates and avoi ...

Is there a way to utilize the 'interval' Rxjs function without triggering the Change Detection routine?

My goal is to display the live server time in my application. To achieve this, I created a component that utilizes the RXJS 'interval' function to update the time every second. However, this approach triggers the Change Detection routine every se ...

How can I simulate keyboard events in Angular using a button click?

I've included separate buttons for Ctrl+z and Ctrl+y functionalities. When these buttons are clicked, I want them to perform the respective undo and redo actions programmatically. Below is the code snippet for this functionality. undoText(event:MouseE ...

Transform them into async/await in JavaScript

Exploring the promise-retry library, I discovered the following syntax: promiseRetry(function (retry, number) { return doSomething() .catch(retry); }) .then(function (value) { // .. }, function (err) { // .. }); Since I am utilizing a ...

Building a Model Class with redux-orm and TypeScriptCreating a new Model Class with

I've been successfully using redux-orm with JavaScript, however, I'm facing issues when trying to convert my code to TypeScript. Even though I have already implemented the render() method in my Folder Model Class, the TypeScript transpiler is sh ...

An effective way to mimic an un-exported (private) function within a user module using Jest

In my code, I have a function that handles API requests called "private" and several other functions that initiate specific requests with configuration objects. For example, in the requestUploadStatementFile file. I want to test these public functions, bu ...

What is the best way to create a continuous loop of images on a never-ending

Many discussions cover similar topics, but I have not yet found a solution to my specific question. Currently, I am working on creating a model for a website and I am interested in incorporating an infinite rotating gallery with a limited number of images ...

Adjusting the alignment of Bootstrap navbar items upon clicking the toggle button

When I click the toggle button on a small screen, my navbar items appear below the search bar instead of aligning with the home and about elements. Below is an image depicting this issue: https://i.stack.imgur.com/4rabW.png Below is the HTML code structu ...

Just systems that have been positively identified

Greetings! I am currently in the process of creating a small online stock management system using PHP. However, my goal is to restrict access to this web app to only certain systems that I designated. I want to ensure that only the systems under my contro ...

JavaScript method to prevent users from entering numbers as the first two characters, with all subsequent characters being numbers only

I need a specific requirement for my form. The textbox field in my form is labeled "DEA License number", and I want it to only allow the user to enter alphabetic characters for the first two characters, followed by numbers afterward. I am looking to impl ...

What is the method for setting and comparing collectionsjs equality?

I'm interested in utilizing the data structure. Within the factory method, you have the opportunity to specify equals and compare parameters: SortedMap(entries, equals, compare). Can anyone provide insight into what the expected formats for these pa ...