Error: The function was not passed as a valid function

Currently, I am in the process of creating a concise 'Engine' class to streamline interactions with Three.js. I have restructured the Render() method from the example into this Engine JS class, as shown below:

const Engine = function () {
  const pub = {},
      scene,
      camera;

  // SNIP: Additional private and public variables and functions...

  pub.Render = function (fixedUpdate) {
    requestAnimationFrame(pub.Render);
    fixedUpdate();
    renderer.render(scene, camera);
  };

  return pub;
}();

To utilize it, I pass a function containing actions that I wish to execute. For instance:

Engine.Render(function () {
    cube.rotation.x += 0.01;
    cube.rotation.y += 0.02;
});

However, when attempting to run this code in Chrome, an error appears: Uncaught TypeError: number is not a function. Upon inspecting Engine.Render's fixedUpdate variable, it seems to be an unusually large number instead of registering as the expected anonymous function.

To verify this behavior, I tried passing a named function handle, like so:

function animation() {
  cube.rotation.x += 0.01;
  cube.rotation.y += 0.02;
}

Engine.Render(animation);

Yet, surprisingly, the outcome remained the same. It appears that the issue may stem from how I am calling the parameter.

Answer №1

Give this a shot:

  pub.Render = function (fixedUpdate) {
    requestAnimationFrame(function () {pub.Render();});
    fixedUpdate();
    renderer.render(scene, camera);
  };

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

Stop the http requests in Angular as the user continually types in the autocomplete input field

Currently, I have an input field that utilizes a material autocomplete component. This component makes calls to the server for results as the user types. While it is working correctly for now with the server returning results in order, I am looking for a ...

Unable to insert HTML code into a div upon clicking an image button

I am in the process of developing a website dedicated to radio streams, and I was advised to utilize Jquery and AJAX for loading HTML files into a div upon button click. This way, users wouldn't have to load an entirely new page for each radio stream. ...

Stopping the timer with clearInterval isn't functioning as expected

I posted my work online here: Instructions on how to reproduce: Click on a green pin on the map to select a station Fill in the fields for name and last name Sign on the canvas A timer should start counting down from 20 minutes If you click on the ...

What is the method for altering the color of the webkit-slider-thumb using JavaScript?

I am looking to adjust the color of an input range using JavaScript instead of CSS. Can someone help me with this request? Current CSS Code: input[type='range']::-webkit-slider-thumb { -webkit-appearance: none; background: goldenrod !importa ...

Is it possible to retrieve server data in a JavaScript file?

EDIT: I accidentally omitted a piece of relevant code I am looking to access the "jsonData" value from my server in my JavaScript file. Can someone guide me on how to retrieve these values? Here is the server-side code: var express = require('expre ...

Tips for displaying a notification when no products match the search criteria

Whenever I use a search filter and there are no products related to the search, I want to display a message saying "No results found." I attempted the code below, but the message does not appear. renderBrandDetails(brands){ if(brands && brands.length & ...

Alter information exclusively when the user is actively viewing my webpage

It's funny how Facebook used a similar technique in the past, Imagine you opened facebook.com, scrolled through your feed for a bit and then decided to open a new tab to read some news. Even though there were updates on your Facebook feed while you w ...

Resetting the caret position in a React Native TextInput occurs when switching the secureTextEntry prop

As I develop a component to wrap the React Native TextInput in my app, I encounter an issue with the caret position resetting to 0 when toggling the secureTextEntry prop for password visibility. To address this problem, I implemented a workaround using a s ...

Issue with the express server's POST method and fetch causing undefined values to appear during a login process

Currently, I am in the process of learning how to create a basic login functionality for a Chrome extension that I am working on. My approach involves collecting a username and password from two input boxes and then sending this information to a server usi ...

Generating interactive sound using Node.js

Issue My current application, a morse code translator, is experiencing difficulties in playing multiple sounds for user input. It seems that only a single sound is played even when the method is called multiple times. Additionally, the sound is being play ...

Strange JSON.parse quirk observed in Node.js when dealing with double backslashes

My coworker encountered an issue while trying to parse a JSON string from another system, leading to unexpected behavior. To illustrate the problem, I have provided a simple code snippet below: // This code is designed for node versions 8 and above con ...

Anticipated to provide a result upon completion of the arrow function with consistent-return

exports.create = (req, res) => { if (!req.body.task) { return res.status(400).send({ message: "Task Can't be empty", }); } const task = new Task({ task: req.body.task, }); task.save() .then((data) => { ...

Tips for incorporating environment variables within a node configuration file

Assuming I have an environment variable $KEY Currently, I am executing KEY=$KEY babel-node build.js //using webpack to create a bundle of my code An issue arises in the JavaScript files bundled by webpack due to an import statement pointing to config.j ...

No data being rendered in jquery jqgrid due to specific conditions set in the JSON object

I've successfully set up a jqgrid that loads data via php, but I'm running into an issue where no results are displayed. Here's how the grid is configured: $(document).ready(function () { $("#list_records").jqGrid({ url: "grid.php", dataty ...

How can I access a method from another JavaScript file (service) in React JS's App.js to make API requests?

Just starting out with React js and trying to utilize REST API data. I've created a separate file named /shared/job-service.js for this purpose. My goal is to call a method from job-service.js in App.js and display the results on the UI. However, I&ap ...

Troubleshooting Custom Error Message Display Issue with Vee-validate and Zod in Vue 3 Composition API

I'm currently experimenting with using vee-validate alongside zod in my project, employing Composition API and custom error messages. One issue that I've encountered is that when I click into the input field and then quickly click outside of it, ...

The property 'clone' is undefined and cannot be read

Currently, I am using Fullcalendar to update events. My goal is to execute an ajax callback to retrieve the edited version of a specific event. The endpoint for this request should be at /controls/:id/edit. To achieve this functionality, I have implemented ...

Sharing data from AJAX calls in Vue using vue-resource

After using Vue resource, I'm attempting to create an AJAX call that is based on the data received from a prior AJAX call. I have successfully bound the data fetched from /me to the userDetails prop. However, when trying to pass userDetails.id into t ...

Chrome Devtool reported an error, but the majority of them are in a null file

Currently grappling with an irksome problem in Vue.js. No matter how hard I try, I just can't seem to pinpoint the error. Even when setting a debugger, all it shows is an empty file. Please take a look at the image provided. Any assistance on identify ...

Scroll automatically to the following div after a brief break

On my website, the title of each page fills the entire screen before the content appears when you scroll down. I am interested in adding a smooth automatic scroll feature that will transition to the next section after about half a second on the initial "ti ...