在JavaScript中:理解奇怪的部分词法环境被解释为代码的范围,而执行上下文是词汇环境的集合,并且它包含超出编写代码的内容.
这些术语的描述在功能上仍然存在重叠,并且不清楚执行上下文的作用或执行方式.
我搜索了 Github 问题和堆栈溢出,每当有人无法让 copilot 工作(没有任何建议)时,每个人都会告诉你更新 vscode、扩展,然后打开“查看”>“输出”。
嗯,我已经将 vscode 和 copilot 更新到最新版本,并且在 Github 上进行了身份验证。当我打开输出时,我可以看到除 Copilot 之外的每个分机的日志。这就是我陷入困境的地方,因为我没有读到任何人提到没有输出时要做什么。
我没有auto价值。如果应用height它,将采用孩子的身高,但是如果应用width它,将采用父母的身高。
该auto值本身没有MDN帖子,并且Google会生成“ 100%VS自动”匹配,而不是“ width:auto VS height:auto”匹配。
为了满足我当前的需求,我希望将一个元素扩展到其孩子的宽度,但总的来说,我希望知道如何处理auto。
.divXS {
width: 100px;
height: 100px;
background: green;
}
.divXXS {
width: 50px;
height: 50px;
background: yellow;
}
.divSM {
width: 200px;
height: 200px;
}
#Father {
background: blue;
border: 3px solid #20295E;
}
#Mother {
background: pink;
border: 3px solid #DB6DBE;
}
#Daughter {
width: 100%;
height: 100%;
}
#Son {
width: auto;
height: auto;
}Run Code Online (Sandbox Code Playgroud)
<div class="divSM" id="Mother">
<div class="divXS" id="Daughter"> …Run Code Online (Sandbox Code Playgroud)在 Firefox 开发者工具规则视图中,选择器是粉红色的。有时灰色的选择器和粉红色的选择器一起。他们在做什么?
在以下代码中,有两个"undefined"实例:
A:
b();
console.log(a);
var a = "Hello World!";
function b() {
console.log("Called b!");
}
Run Code Online (Sandbox Code Playgroud)
这会导致控制台为"a"显示"Undefined".
B:
b();
console.log(a);
function b() {
console.log("Called b!");
}
Run Code Online (Sandbox Code Playgroud)
这会创建"未捕获的ReferenceError:a未定义".在这两种情况下,a都是未定义的,控制台会告诉您.但是,为什么它会根据具体情况选择不同的方式呢?除了undefined和null之外还有几种形式的"undefined"吗?
我很清楚有关此错误的此类问题。但令我困惑的是 Spring 文档明确指出 @WebMvcTest 的全部目的是测试 Web 层而不需要加载应用程序上下文。
来自 Spring文档
测试断言与前面的情况相同。然而,在这个测试中,Spring Boot 只实例化了 web 层而不是整个上下文。在具有多个控制器的应用程序中,您甚至可以要求仅使用 @WebMvcTest(HomeController.class) 实例化一个控制器。
那么,当 @WebMvcTest 的全部目的是在没有应用程序上下文的情况下运行测试时,为什么我会收到有关应用程序上下文的错误呢?
我的代码供参考:
@WebMvcTest(UserController.class)
public class UserController_WebLayerTests {
@Autowired
private MockMvc mockMvc;
@Test
public void shouldReturn401() throws Exception {
mockMvc.perform(get("/api/test")).andDo(print()).andExpect(status().isOk());
}
}
Run Code Online (Sandbox Code Playgroud)
我的日志
java.lang.IllegalStateException: Failed to load ApplicationContext
at org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContext(DefaultCacheAwareContextLoaderDelegate.java:132)
at org.springframework.test.context.support.DefaultTestContext.getApplicationContext(DefaultTestContext.java:124)
at org.springframework.test.context.support.DependencyInjectionTestExecutionListener.injectDependencies(DependencyInjectionTestExecutionListener.java:118)
at org.springframework.test.context.support.DependencyInjectionTestExecutionListener.prepareTestInstance(DependencyInjectionTestExecutionListener.java:83)
at org.springframework.boot.test.autoconfigure.SpringBootDependencyInjectionTestExecutionListener.prepareTestInstance(SpringBootDependencyInjectionTestExecutionListener.java:43)
at org.springframework.test.context.TestContextManager.prepareTestInstance(TestContextManager.java:244)
at org.springframework.test.context.junit.jupiter.SpringExtension.postProcessTestInstance(SpringExtension.java:138)
at org.junit.jupiter.engine.descriptor.ClassBasedTestDescriptor.lambda$invokeTestInstancePostProcessors$6(ClassBasedTestDescriptor.java:350)
at org.junit.jupiter.engine.descriptor.ClassBasedTestDescriptor.executeAndMaskThrowable(ClassBasedTestDescriptor.java:355)
at org.junit.jupiter.engine.descriptor.ClassBasedTestDescriptor.lambda$invokeTestInstancePostProcessors$7(ClassBasedTestDescriptor.java:350)
at java.base/java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:195)
at java.base/java.util.stream.ReferencePipeline$2$1.accept(ReferencePipeline.java:177)
at java.base/java.util.ArrayList$ArrayListSpliterator.forEachRemaining(ArrayList.java:1654)
at java.base/java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:484) …Run Code Online (Sandbox Code Playgroud) 这里的退货声明是否不必要?
var fahrenheit;
var celsius;
function cToFConvert () {
celsius = temperatureInput.value;
fahrenheit = celsius * (9/5) +32;
console.log(fahrenheit);
return fahrenheit;
}
Run Code Online (Sandbox Code Playgroud)
fahrenheit即使我不使用return语句,我也可以获得值.如果变量是在全局范围内声明的,那么这意味着使用返回是多余的吗?
我正在尝试确定闪光灯是打开还是关闭,这样只需一个按钮我就可以打开和关闭闪光灯.这是我的代码:
Camera cam = getCameraInstance(); //A method that opens the cam
Camera.Parameters parameters = cam.getParameters();
System.out.println("Current flash mode " + parameters.getFlashMode());
System.out.println("flash mode off equals to : " + Camera.Parameters.FLASH_MODE_OFF);
System.out.println(parameters.getFlashMode() == Camera.Parameters.FLASH_MODE_OFF);
Run Code Online (Sandbox Code Playgroud)
前两个系统的输出是off.当然我假设因为它们都返回一个off字符串,将==操作符放在它们之间会返回true(因此允许我检查闪存是否打开)但它返回false.知道为什么吗?
我的目标是api 16并在Marshmallow设备上进行测试
据我所知,JS是函数作用域而不是块作用域,这意味着在(括号)内声明的对象不会创建不同的执行上下文.然而:
$('#firstBtn').click(function first() {
console.log("first activated");
});
$('#secondBtn').click(function() {
console.log("second activated");
first();
});
Run Code Online (Sandbox Code Playgroud)
退货Reference Error function is undefined.该函数first在括号内声明,因此从技术上讲,它应该可用于从声明的范围调用它的其他函数.
但这有效:
var callDat = $('#firstBtn').click(function first() {
console.log("first activated");
});
$('#secondBtn').click(function() {
console.log("second activated");
callDat.first();
});
Run Code Online (Sandbox Code Playgroud)
我的假设是,由于对象是函数,声明对象内部的函数可以计算为在不同的函数范围内声明,即使没有花括号.但我希望对此有一个明确的答案.