在现代浏览器(JavaScript 1.8.5 / Firefox 4+)中,根据 ECMAScript 5 规范, undefined 是不可配置、不可写的属性。即使情况并非如此,也要避免覆盖它。
undefined 的属性之一是不可写。
但如果我这样做:
var undefined = 'hello';
var test = undefined;
console.log(typeof test);
//stringRun Code Online (Sandbox Code Playgroud)
这是否意味着我可以覆盖 的值undefined?如果有人这样做会发生什么?JavaScript 应该对此发出警告吗?
我知道这很简单,但我无法得到它.
我有这个代码:
var nietos = [];
nietos.push(nieto.label);
nietos.push(nieto.value);
Run Code Online (Sandbox Code Playgroud)
label是一些字符串,如"Title"和值"Ramones".如果我这样做,我会得到一个简单的数组
["Title", "Ramones"]
Run Code Online (Sandbox Code Playgroud)
我需要创建这个:
[{"01":"Title", "02": "Ramones"}]
Run Code Online (Sandbox Code Playgroud)
我怎样才能将这些推送到nietos数组以便将它们作为对象推送?将使用一些i,k变量生成数字01,02,因为所有这些都在for中.
目前我有这个测试:
import toHoursMinutes from '../../../app/utils/toHoursMinutes';
describe('app.utils.toHoursMinutes', () => {
it('should remove 3rd group of a time string from date object', async () => {
expect(toHoursMinutes(new Date('2020-07-11T23:59:58.000Z'))).toBe('19:59');
});
});
Run Code Online (Sandbox Code Playgroud)
所做toHoursMinutes的就是接收一个 Date 对象并像这样转换它:
export default (date) => `${('' + date.getHours()).padStart(2, '0')}:${('' + date.getMinutes()).padStart(2, '0')}`;
Run Code Online (Sandbox Code Playgroud)
我的本地时间偏移量是-4这样,如果我23:59与进行比较19:59,我的测试通过就可以了,但我想在任何地方运行测试,所以我更喜欢将 的输出toHoursMinutes()与像这样的正则表达式表达式进行比较,检查hh:mm格式:^([0-1]?[0-9]|2[0-3]):[0-5][0-9]$
但是如何使用正则表达式来比较显式字符串呢?
我试过这个:
const expected = [
expect.stringMatching(/^([0-1]?[0-9]|2[0-3]):[0-5][0-9]$/)
];
it.only('matches even if received contains additional elements', () => {
expect(['55:56']).toEqual(
expect.arrayContaining(expected)
);
});
Run Code Online (Sandbox Code Playgroud)
但我得到一个: …
我需要在ajax调用成功时重新加载页面.
我看到了一些代码(不是我的代码),有两种方法:
success : function(obj) {
//code
location.href = location.href;
}
Run Code Online (Sandbox Code Playgroud)
要么
success : function(obj) {
//code
window.location.reload(true);
}
Run Code Online (Sandbox Code Playgroud)
这种行为有什么不同吗?我知道位置和window.location的区别,但在工作方面?
我目前正在努力用文本替换播放/暂停图标,同时仍保持切换动画的方法。
我试图确切地了解哪个JS代码正在渲染图标,然后删除/隐藏它们,以便可以将它们替换为文本
我仍然是JS的初学者,非常感谢您的帮助
var tl = new TimelineMax(),
$videoContainer = $('.cb-video-container'),
$video = $videoContainer.find('.video'),
$playPauseClickArea = $videoContainer.find('.play-pause--click-area'),
$playPauseContainer = $videoContainer.find('.play-pause--container'),
$playIcon = $videoContainer.find('.play-icon'),
$pauseIcon = $videoContainer.find('.pause-icon'),
iconIsToggled = false,
iconEase = Back.easeInOut.config(1.7),
iconDuration = 0.3;
setupVideo();
// functions
function setupVideo() {
TweenMax.set($pauseIcon, {
autoAlpha: 0,
scale: 0
});
TweenMax.set($playPauseClickArea, {
backgroundColor: 'rgba(0, 0, 0, 0.5)'
})
};
function showPaused() {
iconIsToggled = true;
tl.play();
tl.to($playIcon, iconDuration, {
autoAlpha: 0,
scale: 0,
ease: iconEase
}, 0);
tl.to($pauseIcon, iconDuration, {
autoAlpha: 1, …Run Code Online (Sandbox Code Playgroud)我有一个网络应用程序需要访问相机,但我想手动请求相机权限,因为如果网络应用程序自动检测到相机权限,它会“为时已晚”。
我需要的是请求许可,然后我可以渲染一个渲染相机的第 3 方 JavaScript 函数。
使用 React Native 很容易,但是使用普通的 React,对于 Chrome 和 Safari,我找不到一种方法来询问何时需要这些权限。
任何想法?
我在Angular应用程序中有以下代码,html看起来像这样。
<ng-multiselect-dropdown
(onSelect)="onSubstringSelect($event)">
</ng-multiselect-dropdown>
Run Code Online (Sandbox Code Playgroud)
那onSubstringSelect是在组件的.ts部分中:
onSubstringSelect(item: any) {
const dataPois = this.getPois(data);
alert("2nd alert " + dataPois);
// etc
}
Run Code Online (Sandbox Code Playgroud)
getPois(data): any[] {
this.api.getPois(data).subscribe((result: any) => {
alert("1st alert");
return result.pois;
}
}, (error: any) => {
console.error('error', error);
return {};
});
return null;
}
Run Code Online (Sandbox Code Playgroud)
我期望我先拥有alert("1st alert");,然后再alert("2nd alert " + dataPois); 执行警报。为什么?
我有一个碳日期,如:
$new_days_count = Carbon::now();
dd($new_days_count);
Carbon {#764 ?
+"date": "2019-07-20 19:06:49.119790"
+"timezone_type": 3
+"timezone": "UTC"
}
Run Code Online (Sandbox Code Playgroud)
现在,我想为那个时间设置一个特定的小时:分钟:秒,以便:
Carbon {#764 ?
+"date": "2019-07-20 23:59:59.000000"
+"timezone_type": 3
+"timezone": "UTC"
}
Run Code Online (Sandbox Code Playgroud)
我该如何设置?我想设置总是在23:59:59.000000
我正在使用 Papaparse 将 csv 文件转换为 json 对象。
\nAPI 期望的数据是这样的:
\n"data": [\n {\n "id": 1,\n "nombre": "AGUASBLANCAS-AGB",\n "descripcion": "-",\n "it_unidad_generadora": 0\n },\n {\n "id": 425,\n "nombre": "AGUASBLANCAS-AGBQ",\n "descripcion": "-",\n "it_unidad_generadora": 403\n }\n ]\nRun Code Online (Sandbox Code Playgroud)\n但是使用 Papaparse,csv 会被转换为每行的数组,如下所示:
\n"data": [\n 0: ["ID", "NOMBRE", "DESCRIPCI\xc3\x93N", "IT UNIDAD GENERADORA"]\n 1: ["1", "AGUASBLANCAS-AGB", "-", "0"]\n 2: ["425", "AGUASBLANCAS-AGBQ", "-", "403"]\n ]\nRun Code Online (Sandbox Code Playgroud)\n有没有办法用 Papaparse 制作 JSON 对象数组?而不是每行的数组的数组
\n我在运行所有测试时遇到此错误(当我直接加载所涉及的函数的唯一测试时,没有错误)
\nnode:internal/process/promises:246\n triggerUncaughtException(err, true /* fromPromise */);\n ^\n\n[UnhandledPromiseRejection: This error originated either by throwing inside of an async function without a catch block,\nor by rejecting a promise which was not handled with .catch(). The promise rejected with the reason\n"Error: Ha ocurrido un error, por favor intente de nuevo m\xc3\xa1s tarde".] {\n code: 'ERR_UNHANDLED_REJECTION'\n}\nRun Code Online (Sandbox Code Playgroud)\n生成错误的函数的代码块如下所示:
\nasync getMonthRequests(rut, month) {\n try {\n // some code, in the test I'm testing that it fails\n } catch (error) {\n return Promise.reject('Ha …Run Code Online (Sandbox Code Playgroud) javascript ×7
jestjs ×2
arrays ×1
css ×1
date ×1
es6-promise ×1
jquery ×1
json ×1
laravel ×1
object ×1
papaparse ×1
php-carbon ×1
reactjs ×1
reload ×1
rxjs ×1
typeof ×1
typescript ×1