After the webpack is packaged, the this in the js file becomes invalid. How to solve this problem?

will webpack change the variables in the packaged js file? Is this caused by a problem with the version of webpack? Ask for the guidance of the great gods.

part of the code before packaging is as follows: * *

var page = {
    data : {
        date : "2018/1/1 00:00:00",  
        },        
    loadTime : function(){
        var  _this = this; //_this
        var current = Date();
        var seconds = (Date.parse(current)-Date.parse(_this.data.date))/1000;//_this.data.date
        timeObject.days   = Math.floor(seconds/(3600*24));
        }
    }

the loadtime function in the packaged page looks like this (_ this is missing):

loadTime: function () {
      e = Date(),
      n = (Date.parse(e) - Date.parse(this.data.date)) / 1000;
      t.days = Math.floor(n / 86400),
      }

browser error

clipboard.png

Mar.20,2021
The reason why

is missing here is that the useless code is automatically merged when packing.
you first define _ this and then use it only once, so it automatically merges into the result
to achieve your goal, you may need a closure to save the execution context to achieve the function of _ this


you can try to execute the file before packaging. There should also be exceptions. Your question here should not be whether to replace this; or not. It's your this that has a problem


The reason why

_ this is missing should be what @ gaoryrt said.

you may have misunderstood the concept of this. The object that recently called it pointed to by this in
js.
page looks like an object, but in fact it is just a variable name, and its value is the object. If you call its value recently, if there is no object in the outer layer, window,Date.parse usually receives a parameter, which has not formed a local scope, so it doesn't matter whether your this points to window, or not.

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-1b3ba40-2c2a2.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-1b3ba40-2c2a2.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?