A basic problem of functional digital quantity!

var obj = {
    f1: function() {
        var p = new this.f2()
        Object.assign(this, p)
        console.log(1, this)
    },
    f2: function() {
        console.log(2, this)
        this.f3 = function() {
            console.log(3, this)
        }
    }
}

(above is the sample code, and the actual code is Mini Program"s)
now I get this in f2 is a {imageLoaded: examples ()} , why not this pointing to obj , what can I do to add f3 to obj , and also in f2

Page({
    f1: function() {
        console.log(this) //{}
        
        this.imageLoaded = function() {}
    },
    f2: function() {
        const p = new this.f1()
        Object.assign(this, p)
    },
})

<image src="{{item}}" hidden bindload="imageLoaded"></image>

you want Page to receive options as context, but Page has specified context. Can you directly register f3 to implement code logic


sample code is fine.
the this in the actual code can only depend on fate. You specify a this of {} . If you want to have a relationship with Page , that's the problem of the concrete implementation of Page . Generally speaking, all the this of F1 , f2 are incorrect.

MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1ea6117-1da6.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1ea6117-1da6.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?