Leo Liu's blog

Home

About

Archives

JavascriptAlgorithmSort

Sort Algorithm(1): Elementary Sort Javascript Implement - Selection, Insertion, Bubble Sort

Elementary Sort, The slowest and simplest Sort algorithm, time complexity is O(n^2) Bubble SortAs Its name, the bigger element will be like a heavy item, Sinking to the bottom of the water, and the small one will swim up to the surface Here’s the algorithm animation: Bubble Sort javascript code: function bubbleSort(a) { for (let i = a.length - 1; i ..

Read more
Javascript

Implement Your Own Call, Bind, Apply

call,bind,apply these three functions are very useful in everyday development, What exactly did they do? Let’s break it down. calluse case: var person = { name: "leo", sayName(greetings) { console.log(greetings, this.name); }, }; var anotherPerson = { name: "norris", }; person.sayName.call(ano..

Read more
JavascriptObject

What Did new Keyword, Object.create() Do In Javascript

We can use both new and Object.create() implement inherantance in javascript: // new function People(name) { this.name = name; } People.prototype.sayName = function () { console.log(this.name); }; var leo = new People("leo"); // object.create() var People = { name: "liu", sayName() { console...

Read more
loading..
ApiWebDevelopment

RPC, REST, GraphQL - What Are These API Achitectures

I believe many newbie to web Developer have these questions, so let’s talk about it and fiugre out the exact details of these API Achitectures(or specifics) RPC (Remote Procedure Call) In distributed computing, a remote procedure call (RPC) is when a computer program causes a procedure (subroutine) to execute in a different address space (commonly on an..

Read more
Javascript

Var, Let - What's Difference In The For Loop

We’ve all written simple for loops to iterate over arrays and objects countless times. But have you ever stopped to consider how the scope of variables used inside loops works? I recently came across an interesting code snippet that highlighted an important distinction between var and let in this context. for (var i = 0; i < 3; i++) { const log =..

Read more
Javascript

History of javascript module development

Recently I came across an article call The Evolution of JavaScript Modularity from a github Repo, This article is so well-written, thus this is kind of a summary of that article. The Name CollisionFrom the moment of its appearance JavaScript has used the global object window as a storage for all variables defined without the var keyword. In 1995-1999 it ..

Read more
Javascript

The Var, let, Const - What's the Difference?

Aspect var let const Scope Function scope; variable is accessible inside function even if declared after usage Block scope; variable is only accessible inside nearest enclosing {…} Block scope; variable is only accessible inside nearest enclosing {…} Re-declared Can re-declare var anywhere in the function Cannot re-declare let in the same block Can..

Read more
JavascriptFront-endHtml-event

加载JS脚本的三种方法

总结一下使用三种不同的方式加载JS脚本,对DomContentLoaded事件的影响 在本文中,我们将总结一下使用三种不同的方式加载JS脚本,对DomContentLoaded事件的影响。DomContentLoaded事件是指浏览器解析完HTML文档,构建了DOM树后触发的事件,它通常用于执行一些依赖于DOM元素的操作。加载JS脚本有三种方式:默认加载、defer和async,它们分别有不同的特点和影响。 默认加载 默认加载是最常见的一种方式,就是直接在HTML文档中使用标签引入外部脚本。这种方式的特点是: 脚本会按照声明的顺序依次执行。 脚本会阻塞HTML文档的解析和DOM树的构建,直到脚本执行完毕。 脚本会阻塞后面的脚本和样式表的加载和渲染。 脚本会延迟DomContentLoaded事件的触..

Read more
123