請問如何從一個Js調用另一個js的function

請問如何從一個Js調用另一個js的function , thank you

const OtherClass = require(“OtherClassFileName”);

OtherClass.otherMethod();

thank you so much for reply, but i have a error :tired_face: the error message is ‘Simulator: TypeError: mainClass.get is not a function’

NewScript.js

const mainClass = require("HelloWorld");
cc.Class({
    extends: cc.Component,

    properties: {
        // foo: {
        //    default: null,      // The default value will be used only when the component attaching
        //                           to a node for the first time
        //    url: cc.Texture2D,  // optional, default is typeof default
        //    serializable: true, // optional, default is true
        //    visible: true,      // optional, default is true
        //    displayName: 'Foo', // optional
        //    readonly: false,    // optional, default is false
        // },
        // ...
    },

    // use this for initialization
    onLoad: function () {

    },
    
    pageViewClick:function(event,coustom){
    
    var node = event.node;
    this.pageIndex = node.getComponent(cc.PageView).getCurrentPageIndex();
    cc.log("page index"+this.pageIndex);
    const mainClass = require("HelloWorld");
    mainClass.get(this.pageIndex);
    
    
},

 

    // called every frame, uncomment this function to activate update callback
    // update: function (dt) {

    // },
});

HelloWorld.js

var getstart = false;

var page = 3;

const mainClass = require('HelloWorld');

cc.Class({
    extends: cc.Component,

    properties: {
       
        // defaults, set visually when attaching this script to the Canvas
        text: 'Hello, World!',
        
        
        pageView: cc.PageView,
        next: cc.Button,
        
    },

    // use this for initialization
    onLoad: function () {
    //this.pageView.scrollToPage(3);
    
    this.pageView.node.on('event', this.getPage, this);
    
    
    this.next.node.on('click',this.callback,this);
    
    
    
    },

    // called every frame
    update: function (dt) {
        
        if(!getstart){
            
             this.pageView.scrollToPage(page);
             
             getstart = true;
            
            
            
        }
        

    },
    
    callback: function(event){
      
      this.pageView.scrollToPage(2);
      
      cc.log('hihihihihihi')
        
    },
    
    getPage: function(event){
        var i = this.pageView.getCurrentPageIndex();
        
        cc.log('get: '+i)
        
    },
    
    getPageNum: function(num){
     
     cc.log("page index"+num);
 },
 
 get(num){
     
     cc.log("page indexddd: "+num);
     
     
 },
 
    
    
});

i called getPageNum method, the problem still here :cry:

help me :cry:

maybe because you use ‘extends: cc.Component’
you can see this http://www.cocos.com/docs/creator/scripting/access-node-component.html

In NewScript.js, HelloWorld class is assigned to “mainClass”, but “get” method only exists in the instance of HelloWorld class. You should create an instance by keyword “new” first:

const mainClass = require("HelloWorld");
const hello = new mainClass();
hello.get(this.pageIndex);

Remove this line “const mainClass = require(‘HelloWorld’);” in HelloWorld.js, because it creates a circular reference to itself.