我们可以使用for-of循环访问数组元素:
for (const j of [1, 2, 3, 4, 5]) {
console.log(j);
}
Run Code Online (Sandbox Code Playgroud)
如何修改此代码以访问当前索引?我想使用for-of语法实现这一点,既不是forEach也不是for-in.
Object.freeze
或者相反的是Object.seal
什么?是否有一个具有诸如分离之类的名称的功能?
将光标放在代码中的某个位置后,我试图显示所有可能的单词。
当我开始写作/打字时会出现自动完成列表:
但是,我想在打字之前查看所有建议的单词。
我试过了[Cmd] + [Space]
,但它是 MacOS 中搜索的系统快捷方式
有什么想法吗?
new Date()
采用序数并返回一个Date
对象.
做了Date()
什么,为什么会给出不同的时间?
>>> new Date(1329429600000)
Date {Fri Feb 17 2012 00:00:00 GMT+0200 (????? Standard Time)}
>>> Date(1329429600000)
"Tue Mar 06 2012 15:29:58 GMT+0200 (Jerusalem Standard Time)"
Run Code Online (Sandbox Code Playgroud) 我们知道,Groovy语法接受闭包.今天,Java 8还增加了语法闭包.
但是,当我在groovy文件中编写java8闭包时,我收到如下错误:
Person.findAll().stream().filter(e-> e.age > 20)
Run Code Online (Sandbox Code Playgroud)
我们收到此错误:
org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:
Script1.groovy: 7: unexpected token: -> @ line 7, column 39.
Person.findAll().stream().filter(e-> e.controllerId > 0)
^
1 error
Run Code Online (Sandbox Code Playgroud)
然而,以下工作成功:
Person.findAll().stream()
Run Code Online (Sandbox Code Playgroud) 请考虑以下代码:
List<Locale> locales = Arrays.asList(
new Locale("en", "US"),
new Locale("ar"),
new Locale("en", "GB")
);
locales.stream().filter(l -> l.getLanguage() == "en");
Run Code Online (Sandbox Code Playgroud)
我如何获得的大小locales
ArrayList
后申请filter
的,因为locales.size()
给我的尺寸前申请filter
?
假设我们有对象数组.
调用Object.assign(...array)
在具有索引的对象i
覆盖具有索引的对象中的现有属性的那些对象之间进行继承i-1
例如:
var array=[{interf:'IPerson',name:'Someone'},{clss:'Person',name:'Ahmed'},{student:true}];
console.log(
Object.assign(...array) // Object.assign(array[0],array[1],array[2])
)
Run Code Online (Sandbox Code Playgroud)
现在,使用Babel和建议的对象扩展语法,我们可以静态地执行此操作:
{...array[0],...array[1],...array[2]} // spread used for each object not for array
Run Code Online (Sandbox Code Playgroud)
如何动态地做到这一点?
"扩散语法"的上下文重叠.我的意思是如何使用扩展语法:
{}
进行继承?
我试着{...array}
和它返回{0:<array[0]>,1:<array[1]>,2:<array[2]>}
它不是作为输出相同Object.assign(...array)
.
假设我有一个对象数组:
[{'a': 'something', 'b':12},
{'a': 'something', 'b':12},
{'a': 'somethingElse', 'b':12},
{'a': 'something', 'b':12},
{'a': 'somethingElse', 'b':12}]
Run Code Online (Sandbox Code Playgroud)
获取元素的最后一个索引的最最干净的方法是什么,其中a的值为'something'.在这种情况下3.有没有办法避免循环...
如何设置withCredentials=true
到 fetch
其回报的承诺.以下是正确的:
fetch(url,{
method:'post',
headers,
withCredentials: true
});
Run Code Online (Sandbox Code Playgroud)
我认为MDN文档谈到了关于http请求的所有内容,除非这一点:withCredentials
我想使用Javascript在客户端显示咆哮.
我的意思是这个UI组件:
我找到了这个帖子,但是,我找不到一个叫做的对象:topBar
还知道使用:
grep -rl
在文件中查找文本导致发现这个JS:
/**
* PrimeFaces NotificationBar Widget
*/
PrimeFaces.widget.NotificationBar = PrimeFaces.widget.BaseWidget.extend({
init: function(cfg) {
this._super(cfg);
var _self = this;
//relocate
this.jq.css(this.cfg.position, '0').appendTo($('body'));
//display initially
if(this.cfg.autoDisplay) {
$(this.jq).css('display','block')
}
//bind events
this.jq.children('.ui-notificationbar-close').click(function() {
_self.hide();
});
},
show: function() {
if(this.cfg.effect === 'slide')
$(this.jq).slideDown(this.cfg.effect);
else if(this.cfg.effect === 'fade')
$(this.jq).fadeIn(this.cfg.effect);
else if(this.cfg.effect === 'none')
$(this.jq).show();
},
hide: function() {
if(this.cfg.effect === 'slide')
$(this.jq).slideUp(this.cfg.effect);
else if(this.cfg.effect === 'fade')
$(this.jq).fadeOut(this.cfg.effect);
else if(this.cfg.effect === 'none')
$(this.jq).hide();
},
isVisible: …
Run Code Online (Sandbox Code Playgroud) javascript ×7
arrays ×2
ecmascript-6 ×2
java-8 ×2
babeljs ×1
closures ×1
fetch-api ×1
for-of-loop ×1
freeze ×1
groovy ×1
intellisense ×1
java ×1
jsf ×1
lambda ×1
locking ×1
macos ×1
primefaces ×1