草庐IT

Environment_variable

全部标签

javascript - 错误 TS2539 : Cannot assign to 'c' because it is not a variable

我有2个.ts文件,C.ts:exportletc:any=10;A.ts:import{c}from"./C";c=100;编译A.ts时报错:errorTS2539:Cannotassignto'c'becauseitisnotavariable.我该如何解决? 最佳答案 将它放在一个类中,并使其成为静态的exportclassGlobalVars{publicstaticc:any=10;}从任何其他文件导入之后GlobalVars.c=100; 关于javascript-错误TS

javascript - 获取 ReferenceError : Can't find variable: angular

我不熟悉yeoman及其使用的所有工具。我在yeoman中创建了一个测试项目并尝试在jasmine中运行测试规范。我已经使用cmd安装了jasmine插件:npm安装grunt-contrib-jasmine--save-dev在Gruntfile.js中添加了一个jasmine任务jasmine:{src:'/scripts/{,*/}*.js',specs:'test/spec/{,*/}*.js'},当我运行jasmine任务gruntjasmine时出现以下错误:-E:\PersonalProjects\yeoman-projects\test-app>gruntjasmine

javascript - vuejs 配置 : using a global variable?

这看起来很蠢,但我是这样设置的:在config/index.js中:module.exports={API_LOCATION:'http://localhost:8080/api/'}然后在src/app.js我有:importVuefrom'vue'importVueRouterfrom'vue-router'importVueResourcefrom'vue-resource';Vue.use(VueRouter);Vue.use(VueResource);constApp=require("./app.vue");consthome=require("./components/h

javascript - 来自 popup.js 的 Chrome 扩展程序 : Access to variables of a background. js

如果我使用chrome.extension.getBackgroundPage(),我可以像这样访问background.js的变量:背景.js:vartransfer='sometext';弹出.js:chrome.extension.getBackgroundPage().transfer但是this说我只得到一个窗口对象(但也许“窗口”之前的“JavaScript”意味着什么......)。如何访问后台变量? 最佳答案 是的,窗口前的“javascript”一词确实意味着它返回javascript文件(页面)backgroun

javascript - Angular : Select doesn't change selected option on change of bound scope variable

我有一个选择控件。它的选项是从作用域的对象数组动态生成的。在应用程序初始化时,我想通过更改作用域上的绑定(bind)变量来选择特定选项。当select的ng-option返回完整对象时,它不起作用。但是,它在select的ng-option返回字符串时有效。是Angular错误还是我做错了什么?HTML:Doesn'tworkwhenselect'sngModelvalueisobject:{{valueObject|json}}Workswhenselect'sngModelvalueisstring:{{valueString|json}}JS:functionselectCtrl

Javascript 继承 : Parent's array variable retains value

我在这里尝试在JavaScript中使用继承,我发现Parent类中的数组值被Child类继承时出现问题。下面的代码是正常的继承:varParent=function(){this.list=[];};varChild=function(){};Child.prototype=newParent;Child.prototype.constructor=Child;varobj1=newChild;obj1.list.push("hello");console.log(obj1.list);//prints["hello"];当我将新的Child对象(继承包含名为list的数组变量的Pa

Javascript : How to create global functions & variables

我想创建一个可以在元素上使用的新函数,如下所示:document.getElementById("element").myNewFunction();我不是在说这个:document.getElementById("element").myNewFunction=function(){doSomething...}因为这仅适用于该元素,但我应该如何创建全局函数,以便我可以在所有元素(如JavaScript内置的元素)上使用? 最佳答案 使用Element的原型(prototype)来扩展其功能:Element.prototype.m

javascript - 你如何在 JavaScript 中使用 "combine variables"来满足 JSLint?

这个问题在这里已经有了答案:JSLintValidationerror"combinethiswiththepreviousvarstatement"(2个答案)关闭7年前。对于一个学校项目,我正在尝试制作一个网站来做一些事情。为此,我使用了HTML、JavaScript和CSS。我正在使用提供调试提示的编译器。这些提示由JSLint提供。有人告诉我应该将我编写的两个变量组合起来,但我不明白这是什么意思。我已经做了一些研究(在StackOverflow和其他网站上),但所有这些都是想将变量放入数组的人提出来的。谁能告诉我应该怎么做?代码(简化):varx=document.getEle

javascript - jQuery/JavaScript : Defining a global variable within a function?

我有这个代码:varone;$("#ma1").click(function(){varone=1;})$("body").click(function(){$('#status').html("Thisis'one':"+one);})当我点击正文时,它说:这是“一个”:未定义。如何定义要在另一个函数中使用的全局变量? 最佳答案 从函数内部移除var。$("#ma1").click(function(){one=1;}) 关于javascript-jQuery/JavaScript:D

javascript - Phantomjs - 引用错误 : Can't find variable: $

我有一个PhantomJS脚本,当我在本地(Mac)运行它时它可以工作,但是当我在我的Linux服务器上运行它时,它返回以下错误:ReferenceError:Can'tfindvariable:$https://fantasy.premierleague.com/a/statistics/value_form:5712inglobalcode代码是:varpage=require('webpage').create();varfs=require('fs');varargs=require('system').args;page.settings.userAgent='Special