当我尝试在nodejs中运行我的javascript(firebase.js取自https://firebase.google.com/docs/web/setup)时出现错误 ReferenceError:self未定义:
C:\Program Files\nodejs>node.exe c:\Temp\firebase.js
c:\Temp\firebase.js:535
I.prototype.onTokenRefresh=function(){throw this.a.create("only-available-in-window");};I.prototype.onTokenRefresh=I.prototype.onTokenRefresh;I.prototype.setBac
kgroundMessageHandler=function(){throw this.a.create("only-available-in-sw");};I.prototype.setBackgroundMessageHandler=I.prototype.setBackgroundMessageHandler;I
.prototype.delete=function(){D(this.c)};var J=function(a,b){var c={};return c["firebase-messaging-msg-type"]=a,c["firebase-messaging-msg-data"]=b,c};var K=self,
P=function(a){I.call(this,a);var b=this;this.a=new firebase.INTERNAL.ErrorFactory("messaging","Messaging",x);K.addEventListener("push",function(a){return L(b,a)
},!1);K.addEventListener("pushsubscriptionchange",function(a){return N(b,a)},!1);K.addEventListener("notificationclick",function(a){return O(b,a)},!1);this.b=nu
ll};f(P,I);
ReferenceError: self is not defined
at Object.<anonymous> (c:\Temp\firebase.js:535:476)
at Object.<anonymous> (c:\Temp\firebase.js:547:800)
at Module._compile (module.js:571:32)
at Object.Module._extensions..js (module.js:580:10)
at Module.load (module.js:488:32)
at tryModuleLoad (module.js:447:12)
at Function.Module._load (module.js:439:3)
at Module.runMain (module.js:605:10)
at run (bootstrap_node.js:427:7)
at startup (bootstrap_node.js:151:9)
我能做些什么来避免它?
答案 0 :(得分:1)
K被设置为&#39; self&#39; (var K = self),但是&#39; self&#39;尚未定义。如果您从其他来源复制此代码,请确保获得所有这些代码。从它的外观来看,我认为你可以改变自我&#39;到这个&#39;。