Troubleshooting the issue: Uncaught TypeError when trying to read property 'substr' of undefined while passing parameters in JavaScript

In a JavaScript code in my JS file, I have the following function:

var obj, mtl;

init();
animate();
var MYLIBRARY = MYLIBRARY || (function () {
    var _args = {}; // private
    return {
        init: function (Args) {
            _args = Args;
            // some other initializing
        },
        getValue: function () {
            obj = _args[0];
            mtl = _args[1];
        }
    };
} ());

Now, I am trying to pass a value to MYLIBRARY so that I can use it. However, when I try to pass the value like this:

<script src="App_Themes/Assets/js/loaders/JScript.js" type="text/javascript"></script>
         <script type="text/javascript">
             MYLIBRARY.init(["obj/Dress/anarkali.obj", "obj/Dress/anarkali.mtl"]);
             MYLIBRARY.getValue();
        </script>

I encounter the following error:

Uncaught TypeError: Cannot read property 'substr' of undefined

Answer №1

It turns out that the initial question was incorrect. The MYLIBRARY is actually defined in the Jscript.js file and the arguments are initialized afterwards.

As a solution, I have moved the declaration of MYLIBRARY outside of the Jscript.js file.

<script>
var MYLIBRARY = MYLIBRARY || (function () {
var _args = {}; // private
return {
    init: function (Args) {
        _args = Args;
        // some other initialising
    },
    getValue: function () {
        obj = _args[0];
        mtl = _args[1];
    }
};
} ());

</script>

Following that change, the following code snippet was included:

<script type="text/javascript">
         MYLIBRARY.init(["obj/Dress/anarkali.obj", "obj/Dress/anarkali.mtl"]);
         MYLIBRARY.getValue();
    </script>
<script src="App_Themes/Assets/js/loaders/JScript.js" type="text/javascript"></script>

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

The proper way to insert data in JavaScript and PHP

Hello. I have a new function to add a row in my form. However, I recently added a second input field and I am unsure of how to correctly insert it. Below is my JavaScript code: <script type="text/javascript" src="jquery.js"></script> <scri ...

Events in EmberJS that occur after the content has been modified

Need assistance with implementing an alert event for a new tab added to the default ones. Solution: Develop a TabsController Create an initilizerView which uses a list parameter to manage the TabsController.Content Upon insertion of the view, add the ac ...

How come I am receiving a null value for isMatch from bcrypt compare even though the two password strings match exactly?

Currently, I am attempting to authenticate a user based on a password. My approach involves using bcrypt compare to check if the user's requested password matches one stored in a MongoDB database. Despite the passwords being identical, I keep receivin ...

Fade transition not working on Vue image element

I have a Vue component that utilizes swiper.js for slide animations. The desired effect is for an image to transition from right to left, expanding from 300x300px to fill the screen, with content such as a title and description overlaying the text. Curren ...

ability to reach the sub-element dictionaries in typescript

class ProvinciaComponent extends CatalogoGenerico implements OnInit, AfterViewInit { page: Page = new Page({sort: {field: 'description', dir: 'asc'}}); dataSource: ProvinciaDataSource; columns = ['codprovi ...

The Dockerfile for Next13 is unable to locate the server.js file

When using the official Dockerfile from Next with the examples provided, I encounter an error while trying to build the app using a Dockerfile and docker-compose. b78-client-1 | node:internal/modules/cjs/loader:1078 b78-client-1 | throw err; b78-client ...

What is the best way to ensure that the execution of "it" in mocha is paused until the internal promise of "it" is successfully resolved?

const promise = require('promise'); const {Builder, By, Key, until} = require('selenium-webdriver'); const test = require('selenium-webdriver/testing'); const chai = require('chai'); const getUrl = require('./wd ...

How can TypeScript rules be incorporated into a Next.js project without compromising next/core-web-vitals?

In my current NextJS project which is in typescript, I have the following configuration in my .eslintrc.json: { "extends": "next/core-web-vitals" } Now, I want to include additional typescript rules, such as enforcing the rule of n ...

The animation of the model I imported does not match what I created in Blender

After creating a simple object and animation in Blender involving bone rotation, I encountered an issue when importing it into Three.js. Despite the smooth animation resembling what was created in Blender, it appeared rougher and not properly skinned. htt ...

Occasionally, the script tags in Next.js fail to load

https://i.stack.imgur.com/tSrIu.png An error message appears when the script tag fails to load. I have a total of 6 script tags in my code. These scripts are present in my code, but they do not consistently load. However, I can see them when ins ...

Are none of the page links clickable?

Currently, I am in the process of creating a portfolio website. This is my first attempt at coding HTML and CSS from scratch without the aid of a layout template. I've encountered an issue that has me stumped - the links within the container are not ...

Obtain the URL within each promise

I'm currently utilizing Bluebird.js and the request-promise NPM module. My goal is to be able to access the promise URL or item.transactionID as shown in the code snippet below. After numerous attempts, I have not been successful in achieving this. Ho ...

Guide to creating scroll-based animations for a Div element

I've been brainstorming ways to rotate a div as I scroll. My goal is to recreate the effect shown in this codepen. However, I'm struggling to implement scrolling functionality. What I envision is scrolling down causing the word Data to rotate in ...

Ways to prevent the execution of JavaScript code?

I have a website that contains a block where AJAX-loaded code is coming from a remote server. How can I prevent potentially harmful code from executing, especially when it originates from a remote source? Is using the "noscript" tag sufficient to protect a ...

Error: The expression `xmlDoc.load` returns a value of undefined, which is not an object

My current challenge involves loading an XML file using Javascript in IE, Firefox, and Safari. I have yet to find a function that works well across all three browsers. The load function I am currently using is similar to the one found in w3schools tutorial ...

AjaxControlToolkit ReorderList is malfunctioning

I am struggling to utilize a drag & drop control to rearrange a list. My preference is to achieve this using the ReorderList control from the AjaxControlToolkit. Despite multiple attempts, I have not been successful in getting it to function properly. Ever ...

jquery module for retrieving and updating messages

I want to develop a custom plugin that can be utilized in a manner similar to the following example. This isn't exactly how I plan to use it, but it serves as the initial test for me to fully grasp its functionality. HTML: <div id="myDiv">< ...

What is the best way to establish a two-way connection between two arrays?

Within my application, there is an ItemsService responsible for fetching Items from the server and storing them as JSON objects in its cache. These Items may be displayed in various formats such as tables, graphs, or charts. For instance, when setting up ...

"Looking to disable the browser shortcut for ctrl-N and instead trigger a function when this key combination is pressed? Check out the JS Fiddle example provided below

I recently incorporated the library shortcut.js from In my project, I attempted to execute a function when CTRL + N is pressed. The function executed as expected; however, since CTRL + N is a browser shortcut for opening a new window in Mozilla 8, it also ...

PHP: Safely Submitting Scores Using JavaScript

I have developed a PHP file that updates scores in a database. For example: http://domain.com/heli/test.php?id=100001181378824&score=50000 The code in test.php is as follows: mysql_connect(localhost,$user,$password); $id = mysql_real_escape_string($_ ...