这是一种非常常见且有用的做法:
// default via value
var un = undefined
var v1 = un || 1
// default via a function call
var myval = () => 1
var v2 = un || myval()
Run Code Online (Sandbox Code Playgroud)
但是在抛出错误时它不起作用(SyntaxError):
var v3 = un || throw new Error('un is not set!')
Run Code Online (Sandbox Code Playgroud)
有没有办法以同样优雅的方式达到同样的效果?这是恕我直言的很多样板代码:
if (!un) {
throw new Error('un is not set!')
}
var v3 = un
Run Code Online (Sandbox Code Playgroud)
或者是否有任何理论障碍,为什么这不是,也永远不可能?
从 Vue.js 移植到 Nuxt.js 时出现错误。
我正在尝试vue-session
在node_modules
. 它编译成功,但在浏览器中我看到错误:
未定义 ReferenceError 窗口
node_modules\vue-session\index.js
:
VueSession.install = function(Vue, options) {
if (options && 'persist' in options && options.persist) STORAGE = window.localStorage;
else STORAGE = window.sessionStorage;
Vue.prototype.$session = {
flash: {
parent: function() {
return Vue.prototype.$session;
},
Run Code Online (Sandbox Code Playgroud)
所以,我遵循了这个文档:
rewardadd.vue
:
import VueSession from 'vue-session';
Vue.use(VueSession);
if (process.client) {
require('vue-session');
}
Run Code Online (Sandbox Code Playgroud)
nuxt.config.js
:
build: {
vendor: ['vue-session'],
Run Code Online (Sandbox Code Playgroud)
但我仍然无法解决这个问题。
考虑一个用 Java 编写的简单 Lambda:
import com.amazonaws.services.lambda.runtime.Context;
import com.amazonaws.services.lambda.runtime.RequestHandler;
public class Hello implements RequestHandler<Integer, String>{
public String handleRequest(int myCount, Context context) {
return String.valueOf(myCount);
}
}
Run Code Online (Sandbox Code Playgroud)
处理程序接口被定义为RequestHandler<InputType, OutputType>
,但是当我的 Lambda 对事件做出反应并且只是产生一些副作用时,输出类型是不必要的,我必须写这样的东西:
public class Hello implements RequestHandler<SNSEvent, Void>{
public Void handleRequest(SNSEvent snsEvent, Context context) {
...
return null;
}
}
Run Code Online (Sandbox Code Playgroud)
这很烦人。
是否有替代RequestHandler
的void
处理程序?:
public class Hello implements EventHandler<SNSEvent>{
public void handleEvent(SNSEvent snsEvent, Context context) {
...
}
}
Run Code Online (Sandbox Code Playgroud) 一个可以await
是非承诺的,这很好。
所有这些表达式都是有效的,不会导致任何错误:
await 5
await 'A'
await {}
await null
await undefined
Run Code Online (Sandbox Code Playgroud)
等待不承诺有任何可检测的影响吗?为了避免潜在的错误,应该注意哪些行为上的差异?是否有任何性能差异?
以下两行是完全相同还是理论上不同?
var x = 5
var x = await 5
Run Code Online (Sandbox Code Playgroud)
怎么样?有什么例子可以证明区别吗?
PS:根据TypeScript作者,有一个区别:
var x = await 5;
与...不同var x = 5;
;var x = await 5;
将在下一个tern中分配x 5,其中asvar x = 5;
将立即评估。
我可以使用它来获得所需的格式:
SELECT TO_CHAR(12345,'99G999') "Amount" FROM DUAL;
SELECT TO_CHAR(123456,'999G999') "Amount" FROM DUAL;
SELECT TO_CHAR(1234567,'9G999G999') "Amount" FROM DUAL;
Run Code Online (Sandbox Code Playgroud)
有没有一种方法,您不必像这样检查长度?:
select case
when length(my_number) = 5 then TO_CHAR(my_number,'99G999')
when length(my_number) = 6 then TO_CHAR(my_number,'999G999')
Run Code Online (Sandbox Code Playgroud) 我正在使用JWT开发REST API。
登录路由很好,但是组middleware jwt.auth
中的路由器不起作用。
错误:
Symfony \ Component \ Debug \ Exception \ FatalThrowableError:调用未定义的方法Illuminate \ Events \ Dispatcher :: fire()
我的代码:
Route::group(['namespace' => 'Api'], function(){
Route::get('user/login', 'AuthController@login');
Route::group(['middleware' => ['jwt.auth']], function() {
Route::get('auth/me', 'AuthController@me');
});
});
Run Code Online (Sandbox Code Playgroud) 我正在设置一个pin
变量,更新它cy.get()
,然后尝试在之后使用它cy.get()
- 它不允许我这样做。
我也在这里读到这是不可能的:https : //docs.cypress.io/guides/core-concepts/variables-and-aliases.html#Return-Values。
我真的需要使用这个变量才能登录:它是一个生成的 PIN 码,我需要在登录时使用它。
var pin = ""
cy.get('.pin-field').invoke('text').then((text1) => {
pin = text1; //assign text1 value to global pin variable, does not work
cy.log(text1) // this works and logs the value of text1
})
cy.log(pin) //this just logs an empty
Run Code Online (Sandbox Code Playgroud) 我设置了环境变量
MY_APP_MY_MAP_A1=a
MY_APP_MY_MAP_A2=b
MY_APP_JUSTMAP_A1=a
MY_APP_JUSTMAP_A2=b
Run Code Online (Sandbox Code Playgroud)
通过以下方式配置我的 Spring Boot (2.1.7.RELEASE) 应用程序@ConfigurationProperties
:
@SpringBootApplication
@EnableConfigurationProperties(MyApp.MyProperties.class)
public class MyApp {
public static void main(String[] args) {
SpringApplication.run(MyApp.class, args);
}
@Bean
public CommandLineRunner cmd(MyProperties props) {
return args -> {
System.out.println("myMap: " + props.getMyMap());
System.out.println("justmap: " + props.getJustmap());
};
}
@ConfigurationProperties(prefix = "my.app")
@Getter
@Setter
static class MyProperties {
private Map<String, String> myMap;
private Map<String, String> justmap;
}
}
Run Code Online (Sandbox Code Playgroud)
当变量名包含大写字母(驼峰式)时,设置 aMap<String,String>
不起作用,否则一切正常:
myMap: null
justmap: {a1=a, a2=b}
Run Code Online (Sandbox Code Playgroud)
有办法怎么做吗?
javascript ×3
java ×2
aws-lambda ×1
cypress ×1
laravel-5 ×1
nuxt.js ×1
oracle ×1
php ×1
rest ×1
spring-boot ×1
sql ×1
vue.js ×1