javascript

Is Javascript “caching” operations?

假装没事ソ 提交于 2021-02-20 18:03:32
问题 I was implementing the Levenshtein distance function in Javascript, and I was wondering how much time it takes to run it with Wikedia's example ("sunday" & "saturday"). So I used console.time() and console.timeEnd() to determine the time spent for the function execution. for (var i = 0; i < 15; i++) { console.time("benchmark" + i); var result = LevenshteinDistance("sunday", "saturday"); console.timeEnd("benchmark" + i); } Since it was fluctuating between 0.4ms and 0.15ms, I used a loop and I

Is Javascript “caching” operations?

我们两清 提交于 2021-02-20 18:03:07
问题 I was implementing the Levenshtein distance function in Javascript, and I was wondering how much time it takes to run it with Wikedia's example ("sunday" & "saturday"). So I used console.time() and console.timeEnd() to determine the time spent for the function execution. for (var i = 0; i < 15; i++) { console.time("benchmark" + i); var result = LevenshteinDistance("sunday", "saturday"); console.timeEnd("benchmark" + i); } Since it was fluctuating between 0.4ms and 0.15ms, I used a loop and I

Redefinition of variable in node.js

独自空忆成欢 提交于 2021-02-20 17:52:39
问题 The execution of this script: tmp.js, that contains: var parameters = {}; (1,eval)("var parameters = {a:1}"); (1,eval)(console.log(parameters)); node tmp.js produces: {} If we comment out the first statement, and execute again the script, we obtain: { a: 1 } The global scope contains exactly the same variables with the same value, so why console.log displays a different value? 回答1: Because all code you run in Node is running in a Node module,¹ with its own scope, not at global scope. But the

Redefinition of variable in node.js

南楼画角 提交于 2021-02-20 17:52:01
问题 The execution of this script: tmp.js, that contains: var parameters = {}; (1,eval)("var parameters = {a:1}"); (1,eval)(console.log(parameters)); node tmp.js produces: {} If we comment out the first statement, and execute again the script, we obtain: { a: 1 } The global scope contains exactly the same variables with the same value, so why console.log displays a different value? 回答1: Because all code you run in Node is running in a Node module,¹ with its own scope, not at global scope. But the

js实现照片墙效果

情到浓时终转凉″ 提交于 2021-02-20 16:52:58
本次要实现的是一个照片墙的效果,如下图,很多图片随机的摆放在窗口中,当点击到某一张的时候,该张图片出现出现在窗口的水平垂直居中的位置。 首先,我们需要简单的结构处理图片,为了方便操作,引用了一个js库: underscore.js ,因为图片的数量是不固定的,这里我们采用动态添加的方式生成li,再在li里面添加图片。 <! DOCTYPE html > < html lang ="en" > < head > < meta charset ="UTF-8" > < title ></ title > < style > * { margin : 0 ; padding : 0 ; border : none ; list-style : none ; } html, body, ul { width : 100% ; height : 100% ; } #ps { position : relative ; } #ps li { width : 250px ; height : 360px ; box-shadow : 0 0 10px #000 ; } </ style > </ head > < body > < ul id ="ps" ></ ul > < script src ="js/Underscore-min.js" ></ script > < script >

json的序列化与反序列化

荒凉一梦 提交于 2021-02-20 16:50:42
㈠什么是json? JSON(JavaScript Object Notation, JS 对象简谱) 是一种轻量级的数据交换格式。它基于ECMAScript(欧洲计算机协会制定的js规范)的一个子集,采用完全独立于编程语言的文本格式来存储和表示数据。简洁和清晰的层次结构使得JSON 成为理想的数据交换语言。 易于人阅读和编写,同时也易于机器解析和生成,并有效地提升网络传输效率。 是JavaScript用来处理数据的一种格式,大部分是用来处理JavaScript和web服务器端之间的数据交换,把后台web服务器的数据传递到前台,然后使用JavaScript进行处理,例如ajax等,是独立于语言和平台的轻量级的数据交换格式。 ㈡json语法 JSON的语法可以表示以下三种类型的值。  简单值 :使用与 JavaScript 相同的语法,可以在 JSON 中表示字符串、数值、布尔值和 null。但 JSON不支持 JavaScript中的特殊值 undefined。  对象 :对象作为一种复杂数据类型,表示的是一组无序的键值对儿。而每个键值对儿中的值可 以是简单值,也可以是复杂数据类型的值。  数组 :数组也是一种复杂数据类型,表示一组有序的值的列表,可以通过数值索引来访问其中 的值。数组的值也可以是任意类型——简单值、对象或数组。 JSON不支持变量、函数或对象实例

How to apply some style to the table row in angular material table

喜你入骨 提交于 2021-02-20 16:32:26
问题 I have this table : <div class="table-container"> <table mat-table [dataSource]="dataSource"> <mat-divider></mat-divider> <!-- title column --> <ng-container matColumnDef="title"> <th mat-header-cell *matHeaderCellDef> {{ 'NOTIFYCATION.NOTIFY_TITLE' | translate }} </th> <td mat-cell *matCellDef="let element"> {{element.title}} </td> </ng-container> <!-- code column --> <ng-container matColumnDef="description"> <th mat-header-cell *matHeaderCellDef> {{ 'NOTIFYCATION.DESCRIPTION' | translate }}

How to apply some style to the table row in angular material table

天涯浪子 提交于 2021-02-20 16:31:59
问题 I have this table : <div class="table-container"> <table mat-table [dataSource]="dataSource"> <mat-divider></mat-divider> <!-- title column --> <ng-container matColumnDef="title"> <th mat-header-cell *matHeaderCellDef> {{ 'NOTIFYCATION.NOTIFY_TITLE' | translate }} </th> <td mat-cell *matCellDef="let element"> {{element.title}} </td> </ng-container> <!-- code column --> <ng-container matColumnDef="description"> <th mat-header-cell *matHeaderCellDef> {{ 'NOTIFYCATION.DESCRIPTION' | translate }}

干了三年Java后端,你竟然还不知道MySQL的四大隔离级别?

允我心安 提交于 2021-02-20 16:29:18
前言 之前分析一个死锁问题,发现自己对数据库隔离级别理解还不够清楚,所以趁着这几天假期,整理一下MySQL事务的四大隔离级别相关知识,希望对大家有帮助~ 事务 什么是事务? 事务,由一个有限的数据库操作序列构成,这些操作要么全部执行,要么全部不执行,是一个不可分割的工作单位。 假如A转账给B 100 元,先从A的账户里扣除 100 元,再在 B 的账户上加上 100 元。如果扣完A的100元后,还没来得及给B加上,银行系统异常了,最后导致A的余额减少了,B的余额却没有增加。所以就需要事务,将A的钱回滚回去,就是这么简单。 事务的四大特性 原子性: 事务作为一个整体被执行,包含在其中的对数据库的操作要么全部都执行,要么都不执行。 一致性: 指在事务开始之前和事务结束以后,数据不会被破坏,假如A账户给B账户转10块钱,不管成功与否,A和B的总金额是不变的。 隔离性: 多个事务并发访问时,事务之间是相互隔离的,一个事务不应该被其他事务干扰,多个并发事务之间要相互隔离。。 持久性: 表示事务完成提交后,该事务对数据库所作的操作更改,将持久地保存在数据库之中。 读者福利:关注公众号:麒麟改bug,获取整理好的MySQL500多页学习笔记和面试题资料(1184页PDF文档) 事务并发存在的问题 事务并发执行存在什么问题呢,换句话说就是,一个事务是怎么干扰到其他事务的呢?看例子吧~ 假设现在有表

uni-app如何解决在for循环里调用异步请求获取数据顺序混乱问题?

寵の児 提交于 2021-02-20 16:22:02
总结/朱季谦 先前有一次做uni-app的js接口对接时,遇到过这样的情况,在for循环里,调用一个异步请求时,返回来的值顺序是乱的,因此,在以下的代码里,push到数组里的值,每次的顺序可能都是不一样的,造成这样一个原因,是for循环是单线程的,异步请求是多线程的,f往往在for循环结束了,异步请求还没有结束。 that.list = res.datas.class_list; for ( var i=0;i<that.list.length;i++ ){ that.list[i].tlist = [] var url = "w=goods_class&gc_id=" + that.list[i].gc_id.substring(2 ); that.thtxb_ajax_request(url, {}).then((res) => { that.tlist.push(res.datas.class_list) }) } 在uni-app框架里,遇到这样的类似代码时,可以用递归算法来避免for循环结束了,异步请求还没有结束的问题,将上面的代码修改成递归形式,如下: that.list = res.datas.class_list; var i = 0 ; getImg(); function getImg() { if (i >= that.list.length) {