scope 相关问题

范围是一个封闭的上下文,其中值和表达式相关联。使用此标记可以了解不同类型范围的问题以及范围可能不清楚的问题。

为什么我可以在 if 语句中重新声明与函数参数同名的变量?

下面是我在尝试实现 Jquery CSS 函数版本时遇到的解决方案的简单版本。 函数 CSS(属性, 值) { ... 如果(值===未定义){ ...

回答 1 投票 0

在 if 语句中重新声明与函数参数同名的变量

下面是我在尝试实现 Jquery CSS 函数版本时遇到的解决方案的简单版本。 函数 CSS(属性, 值) { ... 如果(值===未定义){ ...

回答 1 投票 0

“格式”未在此范围内声明出现错误

#包括 #包括 使用命名空间 std; 无效日志(整数结果){ 计算 << "then his age is " << result << endl; if (result > 50)...

回答 1 投票 0

Vue:“TypeError:handler.apply 不是函数”-($emit 在 jQuery 侦听器回调中)

我已经在 vue 组件内的元素上初始化了 jQuery 插件。在初始化函数中,我有一个“$(document).ready(function()”,这意味着“this”在内部不起作用。所以我使用...

回答 1 投票 0

Powershell:导出/导入 DHCP 范围

我需要将 dhcp 范围从服务器 A(包括保留和地址租用)导出到服务器 B。 要从服务器 A 导出,我使用以下命令: 导出-DhcpServer -计算机名 A -ScopeId 10....

回答 1 投票 0

当函数由于实现未知而无法重写时,如何访问函数调用的参数?

我有一个函数返回函数。内部函数在其主体中使用父函数的参数。然后我列出了通过调用具有不同的父函数而生成的函数列表...

回答 3 投票 0

如何在 JavaScript lambda 函数中获取变量的固定值?

我有一个函数返回函数。内部函数在其主体中使用父函数的参数。然后我列出了通过调用具有不同的父函数而生成的函数列表...

回答 1 投票 0

Javascript,从函数外部调用嵌套函数或从另一个函数内部调用它

是否可以从原始函数外部或另一个函数内部调用嵌套在函数内的函数? 所以在这个例子中,当 func_1 第一次被调用时......

回答 1 投票 0

有没有办法使用 using 指令或类似指令访问枚举类中的所有枚举?

我有一个枚举类,用于清楚地存储传递到计算器解析器的标记类型。枚举类如下所示: 枚举类 TokenKind { 数字, 白S...

回答 1 投票 0

清除iframe内容(包括它的JS全局范围)你好世界<\/title><\/head><body><h1>你好世界<\/h1><scri...</desc> <question vote="4"> <p>我正在像这样动态创建一个 iframe:</p> <pre><code>let code = "<html><head><title> hello world <\/title><\/head><body><h1> hello world <\/h1><script>const h1 = document.querySelector('h1'); h1.style.color = 'red'<\/script><\/body><\/html>" const iframe = document.createElement('iframe') document.body.appendChild(iframe) const content = iframe.contentDocument || iframe.contentWindow.document content.open() content.write(code) content.close() </code></pre> <p>然后我将其内容更改为这样:</p> <pre><code>code = "<html><head><title> bye world <\/title><\/head><body><h1> bye world <\/h1><script>const h1 = document.querySelector('h1'); h1.style.color = 'red'<\/script><\/body><\/html>" content.open() content.write(code) content.close() </code></pre> <p>但我收到以下错误:<pre><code>SyntaxError: redeclaration of const h1</code></pre>,因为 JavaScript 被注入到 iframe 中。</p> <p>在向 iframe 写入新代码之前,有什么方法可以清除 iframe 内的全局变量范围吗?我已经尝试过 <pre><code>iframe.contentWindow.location.replace('about:blank')</code></pre> 以及 <pre><code>iframe.src = 'about:blank'</code></pre> 但这并不能清除它的内部 JS 变量范围。 (我也遇到同样的错误)</p> <p>我意识到我可以废弃整个 iframe 并创建一个新的 iframe,但我将每秒更换几次代码,并且我希望有一种成本更低的方法来更新它。</p> </question> <answer tick="false" vote="0"> <p>您可以用花括号 <pre><code>const</code></pre> 将动态 <pre><code>let</code></pre> 变量中的 <pre><code>content</code></pre> 和 <pre><code>{}</code></pre> 声明括起来,创建块作用域。这是解决重新声明错误的简单方法。</p> <pre><code>// Note the added braces {} within the <script> let code = "<html><head><title> hello world <\/title><\/head><body><h1> hello world <\/h1><script>{ const h1 = document.querySelector('h1'); h1.style.color = 'red' }<\/script><\/body><\/html>" </code></pre> <p>可能更好的方法是首先删除 DOM 中已存在的所有 iframe,然后在需要添加内容时重新创建 <pre><code>iframe</code></pre>。</p> <pre><code>const updateIframe = (code) => { const iframe = document.createElement('iframe') document.body.querySelector('iframe')?.remove() document.body.appendChild(iframe) const content = iframe.contentDocument || iframe.contentWindow.document content.open() content.write(code) content.close() } </code></pre> </answer> </body></html>

我正在动态创建一个 iframe,如下所示: 让代码=“你好世界<\/title><\/head><body><h1>你好世界<\/h1><scri...</desc> <question vote="4"> <p>我正在像这样动态创建一个 iframe:</p> <pre><code>let code = "<html><head><title> hello world <\/title><\/head><body><h1> hello world <\/h1><script>const h1 = document.querySelector('h1'); h1.style.color = 'red'<\/script><\/body><\/html>" const iframe = document.createElement('iframe') document.body.appendChild(iframe) const content = iframe.contentDocument || iframe.contentWindow.document content.open() content.write(code) content.close() </code></pre> <p>然后我将其内容更改为这样:</p> <pre><code>code = "<html><head><title> bye world <\/title><\/head><body><h1> bye world <\/h1><script>const h1 = document.querySelector('h1'); h1.style.color = 'red'<\/script><\/body><\/html>" content.open() content.write(code) content.close() </code></pre> <p>但我收到以下错误:<pre><code>SyntaxError: redeclaration of const h1</code></pre>,因为 JavaScript 被注入到 iframe 中。</p> <p>在向 iframe 写入新代码之前,有什么方法可以清除 iframe 内的全局变量范围吗?我已经尝试过 <pre><code>iframe.contentWindow.location.replace('about:blank')</code></pre> 以及 <pre><code>iframe.src = 'about:blank'</code></pre> 但这并不能清除它的内部 JS 变量范围。 (我也遇到同样的错误)</p> <p>我意识到我可以废弃整个 iframe 并创建一个新的 iframe,但我将每秒更换几次代码,并且我希望有一种成本更低的方法来更新它。</p> </question> <answer tick="false" vote="0"> <p>您可以用花括号 <pre><code>const</code></pre> 将动态 <pre><code>let</code></pre> 变量中的 <pre><code>content</code></pre> 和 <pre><code>{}</code></pre> 声明括起来,创建块作用域。这是解决重新声明错误的简单方法。</p> <pre><code>// Note the added braces {} within the <script> let code = "<html><head><title> hello world <\/title><\/head><body><h1> hello world <\/h1><script>{ const h1 = document.querySelector('h1'); h1.style.color = 'red' }<\/script><\/body><\/html>" </code></pre> <p>可能更好的方法是首先删除 DOM 中已存在的所有 iframe,然后在需要添加内容时重新创建 <pre><code>iframe</code></pre>。</p> <pre><code>const updateIframe = (code) => { const iframe = document.createElement('iframe') document.body.querySelector('iframe')?.remove() document.body.appendChild(iframe) const content = iframe.contentDocument || iframe.contentWindow.document content.open() content.write(code) content.close() } </code></pre> </answer> </body></html>

回答 0 投票 0

在单独的 PHP 脚本中访问全局变量?

我正在尝试从 PHP 脚本导入一些变量。这看起来很简单,但我无法让它发挥作用。 该脚本包含一些全局变量,如下所示: $server_hostname = "本地主机"; $server_da...

回答 7 投票 0

R 公式/表达式中标识符的范围

我正在使用 ggplotify 中的 as.ggplot 来包装 circlize 包中的一些和弦图,这样我就可以使用拼凑的方式很好地排列它们。但是,由于 as.ggplot 将公式或表达式作为

回答 1 投票 0

如何为此 SQL 查询编写 Rails 范围

我有一个通过多个条件从数据库获取行的问题。 我有一个表 Slot 和 SlotAlteration。 该槽有一个 time_off_id 字段。 SlotAlteration 有两列:slot_id 和 action。行动...

回答 1 投票 0

Visual Basic 中 for 循环计数器的范围

考虑以下事项 暗淡 nofTries 作为整数 对于 nofTires=1 到 5 if(条件) 退出... 下一个 由于拼写错误,循环计数器与声明的变量不同。然而,尽管&...

回答 1 投票 0

如何获取datadog应用程序关键范围

我正在尝试访问多个datadog api,并且要访问它们,我需要datadog的api和应用程序密钥。但是有没有办法检查应用程序密钥的范围或权限

回答 1 投票 0

VScode 自定义 css 括号颜色不起作用

我想更改CSS代码中{符号的颜色,但它不起作用。 请参阅下面 css 代码中的 {: 在上面的代码中,“{”看起来像黄色,即使我应用了自定义......

回答 1 投票 0

event 是回调链中任何地方都可以访问的全局变量吗?

我只是在使用 DOM 和 Javascript 来玩弄事件监听器,并注意到了这一点: 函数链(消息){ console.log(消息,事件); } 函数 onClick() { 被锁起来('身体被清除了...

回答 2 投票 0

Fullcalendar v5 - 如何调用已经初始化和渲染的日历

我有一个初始化的日历: $(文档).ready(函数(){ var calendarEl = document.getElementById("日历"); var 日历 = new FullCalendar.Calendar(calendarEl...

回答 2 投票 0

Kotlin 中的局部变量和函数每次调用函数时都会重新创建吗?

考虑以下代码: 类 Foo { 有趣的酒吧(){ val 局部变量 = 1 有趣的本地函数(){ // ... } // 其余代码 } } 每次我打电话给酒吧...

回答 1 投票 0

为什么 print(num) 打印'0'? num 是全局变量,我在局部函数中将 num 更改为“6”

“这是我的代码。当我编译这段代码时,我期望‘print(num)’打印‘6’。我期望背后的原因是,首先,变量‘num’是全局的。因此,在第一行,'num' ...

回答 1 投票 0

© www.soinside.com 2019 - 2024. All rights reserved.