Results 1 to 1 of 1

Thread: Dynamic method for speed optimisation

  1. #1
    Assadministrator kung foo man's Avatar
    Join Date
    Jun 2012
    Location
    trailerpark
    Posts
    2,014
    Thanks
    2,110
    Thanked 1,086 Times in 753 Posts

    Dynamic method for speed optimisation

    I am currently porting some JavaScript code and I don't know the best way to port over such code:

    PHP Code:
    function verySlowCalculationOnlyDoThisOnce() {
        
    console.log("logging slow calculation");
        return 
    "bye";
    }

    Test = function(name) {
        
    this.name name;
    }

    Object.assign(Test.prototype, {
        
    hello: function() {
            
    console.log("hello " this.name)
        },

        
    bye: (function() {
            var 
    byeMessage verySlowCalculationOnlyDoThisOnce();
            return function() {
                return 
    byeMessage ", " this.name "!";
            }
        }())
    }) 
    The bye method basically prepares a part of the return value only once, every test = new Test("you") will reuse the result of the slow function.

    How to rewrite such code for TypeScript?

    The actual real life example is this:

    https://github.com/playcanvas/engine...4.js#L418-L452

    The three Vec3 are allocated once to prevent garbage collection.
    timescale 0.01

  2. The Following User Says Thank You to kung foo man For This Useful Post:

    kubislav23 (24th November 2018)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •