Hi, I am following the session to make some test, but when I execute createFourStopwatchesDemo the safari ended with not any result, it should log more infos like 'StopWatch started'...
Environment :
Mac OSX 11.4
Safari Technology Prview 14.2
The Safari console only shows like below When I execute 'createFourStopwatchesDemo()'
Here is my code.
//Example1
//class with public variable and function
class StopWatchWithOneButton {
_startTime = 0;
click(){
if (!this._startTime) {
this.start();
}else{
this.stop();
}
}
start() {
this._startTime = Date.now();
console.log('StopWatch started');
}
stop() {
let duration = Date.now() - this._startTime;
this._startTime = 0;
console.log('StopWatch stopped after %d ms', duration);
}
}
//class with private variable and function
class PrivateStopWatchWithOneButton {
#_startTime = 0;
static #stopWatchCount = 0;
click(){
if (!this.#_startTime) {
this.#start();
}else{
this.#stop();
}
}
#start() {
PrivateStopWatchWithOneButton.#stopWatchCount++;
this.#_startTime = Date.now();
console.log('StopWatch started');
}
#stop() {
PrivateStopWatchWithOneButton.#stopWatchCount--;
let duration = Date.now() - this.#_startTime;
this.#_startTime = 0;
console.log('StopWatch stopped after %d ms', duration);
}
}
function sleep(ms) {
return new Promise(resolve => setTimeout(resolve, ms));
}
async function demo(){
// console.log(StopWatchWithOneButton._startTime);
var counter = new StopWatchWithOneButton();
counter.click();
console.log('sleep for a while,' + counter._startTime);
await sleep(2000);
console.log('ake up');
counter.click();
//private #_startTime
var priCounter = new PrivateStopWatchWithOneButton();
// console.log('sleep for a while of Private:' + priCounter.#_startTime);//syntax error
priCounter.click();
await sleep(2000);
priCounter.click();
}
//Example2: weak reference
//WeakRef(obj): create weak reference to an object
//use FinalizationRegistry to delete object automaticaly
const allStopWatches = new Map();
var nextAvailableIdentifier = 1;
function removeStopwatch(identifier){
allStopWatches.delete(identifier);
}
const finalizationRegistry = new FinalizationRegistry(removeStopwatch);
function createStopwatch(){
let identifier = nextAvailableIdentifier++;
let stopwatch = new StopWatchWithOneButton();
allStopWatches.set(identifier, new WeakRef(stopwatch));
finalizationRegistry.register(stopwatch, identifier);//the first parameter is an object
return stopwatch;
}
function clickAllStopwatches(){
for(let weakStopwatch in allStopWatches){
//weakStopwatch.deref(): Get the element from the weak reference, if it still exists
weakStopwatch.deref()?.click();
}
}
function createFourStopwatchesDemo(){
for (let i = 0; i < 4; i++) {
let currStop = createStopwatch();
}
clickAllStopwatches();
}
Appreciate for reply in advance ~
Post
Replies
Boosts
Views
Activity
Since I am not familiar with the JavaScript, it will spend days for me to experience these new features, could you send me a copy of the example code? many thanks, my email is cveric AT foxmial.com.
Hi,everyone , Recently I update my iphone 12pro max system to iOS14.6 system , One of the HTTPS request connect to our server works fine on iOS14.5.1 and eariler iOS versions, but it fails only on iOS14.6,the error message shows like below :
Error Domain=NSURLErrorDomain Code=-1202 "此服务器的证书无效。您可能正在连接到一个伪装成“a.b.c.com”的服务器,这会威胁到您的机密信息的安全。" UserInfo={NSURLErrorFailingURLPeerTrustErrorKey=<SecTrustRef: 0x28103fd50>, NSErrorFailingURLKey=https://a.b.c.com/path/to/specific/work/get, NSErrorFailingURLStringKey=https://a.b.c.com/path/to/specific/work/get, NSLocalizedDescription=此服务器的证书无效。您可能正在连接到一个伪装成“a.b.c.com”的服务器,这会威胁到您的机密信息的安全。}
but we had double check the certicicate of the service, pretty sure it's ok, and the certificate was approved by go_daddy, but it only happens on iOS14.6, and now all of our user update to iOS14.6 encountered this problem, anyone can help, thanks a million.