Encountered a TypeError: The function _this.settings is not defined - Dealing with integration of barba.js and three.js

I'm currently working on a website that utilizes barba.js. Within the "slider" page, there is a three.js scene integrated. Initially, when I open the page everything functions as expected. However, if I navigate from the slider page to the home page and then return back to the slider page, an error occurs:

Uncaught (in promise) TypeError: _this.settings is not a function

The script responsible for controlling the slider page is Sketch.js.

import * as THREE from 'three';
import TextTexture from 'three.texttexture';
import TextSprite from '@seregpie/three.text-sprite';
import gsap from 'gsap';
import { Power2 } from 'gsap';
import layout from './Layout'
import { TimelineMax } from "gsap/all";

// Code snippet continues...

// The error originates at:
    this.initiate( ()=> {
      this.setupResize();
      this.settings();
      this.addObjects();
      this.resize();
      this.clickEvent();
      this.play();
    })
  
// This error is within line 193:
  Promise.all(promises).then(() => {
    cb();
  });

The Router.js script handles the routing functionality in Barba.js:

import barba from '@barba/core'
import barbaPrefetch from '@barba/prefetch'

// Code snippet for the Router.js script...

Additionally, the Application.js script includes the following code:

import Router from './Router'

import * as THREE from './three.js';
import TextTexture from 'three.texttexture';
import TextSprite from '@seregpie/three.text-sprite';

import Sketch from './Sketch';

import layout from './Layout'
import iman from './InstanceManager'
import cursor from './Cursor'
import initiaLoader from './InitialLoader'

// More code within Application.js...

If you need further assistance or clarification, feel free to ask. Thank you!

Answer №1

It seems like the issue lies within the specific class method mentioned below...

  settings() {
    let that = this;
    //if(this.debug) this.gui = new dat.GUI();
    this.settings = {progress:0.5};
    // if(this.debug) this.gui.add(this.settings, "progress", 0, 1, 0.01);

    Object.keys(this.uniforms).forEach((item)=> {
      this.settings[item] = this.uniforms[item].value;
      //if(this.debug) this.gui.add(this.settings, item, this.uniforms[item].min, this.uniforms[item].max, 0.01);
    })
  }

The problem arises when settings is initially declared as a method, but then during the execution of this.settings(), it gets redefined as an object.

As a result, when attempting to run this.settings() again, it encounters an error. Here's a concise example demonstrating the issue.

class Test {
  constructor() {
    this.v = 42;
  }
  
  settings() {   
    console.log( 'In settings function' );
    this.settings = {a:1};
  }
}

t = new Test();

// First call to settings() succeeds, but changes settings from function to object
t.settings();   

// Second call to settings() fails due to settings being an object instead of a function
t.settings();   

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

Guide on adding JSON data from a web service whenever a function is invoked in AngularJS

I am currently calling the getData function every second and everything is working fine except for the appending functionality. Whenever the function is called, AngularJS replaces the old data with new data, but I actually want to append the new data aft ...

Center Vertically Using CSS Flexbox

Hey there, I'm currently facing an issue with aligning my website's logo vertically in the middle with my navigation link list. I have attempted to use "vertical-align: middle" on my div columns but it doesn't seem to be working. Right now, ...

Issue with generating WebGL shaders

As I embark on creating a basic application in WebGl and JavaScript following online tutorials, I encountered a peculiar issue while working on some fundamental shaders. The function responsible for generating the shader program presents itself as follows: ...

Ensure that the link's color remains constant and remove any styling of text-decoration

Attempting to create a customized header. My goal is to change the color and remove text decoration in the navbar. Below is my code snippet: ReactJS: import React from 'react'; import './Header.css'; function Header() { return ( ...

Ways to eliminate a specific Chip from Autocomplete outside of material UI

Seeking assistance with displaying selected values as <Chip /> outside of the <TextField /> in <Autocomplete />. The issue lies in deleting these chips and updating the selected prop within <Autocomplete />. Any suggestions or solut ...

What is the best way to create a jQuery object that encapsulates a snapshot of a DOM element?

Recently, I discovered that a JQuery object retains a reference to a DOM object. As the HTML is modified, the context of the JQuery object also changes. However, my concern now is how to log these changes without altering the history records of the JQuer ...

Name is the only piece of information that does not get stored in the

I'm struggling with my AJAX script that sends data to the database. Everything goes into the database except for $name and $n. My code is too long to share here, but I would really appreciate some help as my final year project submission deadline is a ...

Combining platform-express and platform-fastify for optimal performance

I am currently working on a NestJS application and my goal is to upload files using the package @types/multer. However, I encountered an issue while following the guidelines from the official documentation: https://i.sstatic.net/JCX1B.png Upon starting ...

On mobile devices, the height of the absolutely positioned element is larger than its

I currently have an element with a background image that includes an absolutely positioned element at the bottom. As the screen width decreases, the height of the absolutely positioned element increases and surpasses the parent element. Since absolutely p ...

Is your Material JS radio button disable feature malfunctioning following an upgrade to jQuery 3.4?

Recently, I updated the jquery to version 3.4 and material.js to version 1.1.0. Surprisingly, after the jquery upgrade, the code $(".id").attr("disabled", "disabled"); stopped working. This issue seems to occur only in some ve ...

Adding JavaScript to dynamically loaded AJAX content

I'm new to AJAX and JavaScript and unsure of how to get it working. Here is the website: When you click on portfolio images, the details load via AJAX. I want to create a slideshow for projects with multiple full-sized images. However, due to the co ...

Send image data in base64 format to server using AJAX to save

My goal is to store a base64 image on a php server using the webcam-easy library (https://github.com/bensonruan/webcam-easy). I added a button to the index.html file of the demo: <button id="upload" onClick="postData()" style=" ...

Give a response in ISO string

Hey everyone, I'm running into an issue when trying to access a date property in an array of objects from another component using props. When I try to convert it to a string using the 'toISOString()' method, I get an error saying 'toISO ...

Creating a Dynamic Dependent Dropdown with Jquery and Ajax in PHP

As a newbie in coding, I stumbled upon some valuable information to enhance my register form using Ajax. While the PHP files seem to be functioning correctly, I suspect that the JS file is not performing as expected. In the register form, you'll find ...

The preflight request's response failed to meet the access control criteria due to the absence of the 'Access-Control-Allow-Origin' header

I encountered an issue while using ngResource to call a REST API hosted on Amazon Web Services: Upon making the request to , I received the following error message: "XMLHttpRequest cannot load. Response to preflight request doesn't pass access cont ...

Bower fails to add components during installation

For my current project, I have been utilizing bower locally to handle JavaScript dependencies with no issues. However, today I encountered a problem when attempting to initiate a new project by reusing code from previous projects. Specifically, I tried to ...

Using Jmeter's JSON Extractor for parsing response and extracting token value

Currently facing an issue with extracting the "webToken" response. I have attempted using both $..webToken and $.webToken as JSON path expressions, but no luck so far. Any suggestions on how to correctly extract this information? This is for use in JMete ...

Verify the definition of the checkbox

I'm attempting to determine whether a checkbox is defined and unchecked. When the page loads, my checkbox is disabled and I receive an error indicating that it is undefined. I attempted to create a condition to prevent the error but was unsuccessful. ...

Avoiding PHP Execution When Loading From Browser Cache?

One thing I'm trying to understand is how sites like Facebook keep their dynamically generated sidebars, such as the "People you may know," consistent even when users navigate back and forth through their browsing history. On my own site, however, eve ...

Error: Unable to assign values to undefined properties (specifically 'styles') when using withLess, withSass, or withCSS in next.config.js within Next.js

I have been attempting to set up a NextJS 12 project with custom Ant Design. Following some examples I found, it seems I need to configure my next.config.js file with the libraries @zeit/next-sass, @zeit/next-less, and @zeit/next-css. However, when I try t ...