跳至主要内容

博文

目前显示的是标签为“Javascript”的博文

[Resources] Golang, Kotlin, JS and Misc

周末看的几篇文章提到了一些有用的资源,记录一下: - Golang 1. [awesome-go](https://github.com/avelino/awesome-go) 2. [Effective Go](https://go.dev/doc/effective_go) - Kotlin 1. [Coding Conventions](https://kotlinlang.org/docs/coding-conventions.html) - JavaScript 1. [Prototype Chain](https://developer.mozilla.org/zh-CN/docs/Web/JavaScript/Inheritance_and_the_prototype_chain) - Web 1. [MS Restful API Guideline](https://github.com/microsoft/api-guidelines/blob/vNext/Guidelines.md) 2. [Hardening Your HTTP Security Headers](https://www.keycdn.com/blog/http-security-headers)

定制 Blogger 的页面模板以支持 Markdown 内容

换了一个新的页面模板,于是需要重新配置HTML template,否则博文中使用的markdown无法被正确显示在页面上。 幸亏谷歌的cached page还可以找到原本的解决方案, <!-- 2016.03: customize the page to use showdown.js (for markdown) and highlight.js (for code highlight), also utilise AngularJS directive for parsing <div data-markdown> --> <script src='https://ajax.googleapis.com/ajax/libs/angularjs/1.4.9/angular.min.js'></script> <script src='https://cdnjs.cloudflare.com/ajax/libs/showdown/1.3.0/showdown.min.js'></script> <link href='//cdnjs.cloudflare.com/ajax/libs/highlight.js/9.2.0/styles/default.min.css' rel='stylesheet'/> <script src='//cdnjs.cloudflare.com/ajax/libs/highlight.js/9.2.0/highlight.min.js'></script> 首先要添加几个脚本,包括 1. Showdown 用来将 Markdown 的脚本转换为 HTML。 2. Hightlight 用于高亮显示代码,不过这个功能貌似还没有怎么用到。 3. Angular (1.x) 如果不想要用像是 jQuer 这样的脚本来操作 DOM,可以依赖 Ng 的directive来自动识别 `markdown` attribute 直接替换 DOM 内的文本。 然后在末尾添加一段 `script` 脚本定义...

初探 ReactJS

在Youtube上看了一个名为 [Getting Started with React.js](https://www.youtube.com/watch?v=8HkVHbJZeWY) 的视频。 The DOM is EXPENSIVE to update. Virtual DOM is a lightweight DOM representation. Virtual DOM defines pure render function: f(d) = v f(d') = v' diff(d, d') = changes diff(d', d) = undo 由于 React.js 实现了高效的 diff 算法,使得 Virtual DOM 的更新最终被反映到对应的 DOM 节点上,所以性能上的损失并不明显。 Virtual DOM 支持 State 和 Props 两种概念。props 是 immutable 的,从 Parent component 传入的属性,例如 `className` 或是 `isExpanded`。state 是内部状态,从不对外暴露,在设计的时候应当尽量 minimum。state 是由 common ancestor 来管理的。 最基本的例子,在 id 为 "example" 的页面元素内添加一个 virtual DOM ` `。 // JavaScript React.renderComponent( React.DOM.h1(null, 'Hello world!'), document.getElementById('example') ); // JSX React.renderComponent( Hello world! , document.getElementById('example') ); // Live script react.render-component...

Trailing Comma in JSON String

“遵循标准和实现自有的特性,这二者之间是存在一个平衡点的。在我看来,user-friendly可以作为这一平衡点的参考标准之一。” Javascript中使用JSON字符串来描述object的时候,name/value pair之间是以逗号来分割的,例如: { name: 'jlazy', city: 'shanghai', zipcode:'200001' } 这个语法与C、C++、Java和C#中定义数组的语法类似,但是有一个很大的区别,就是最后一个name/value pair后面不应该有逗号。而C家族的数组定义中,是允许存在trailing comma的,例如: int dim[] = { 32, 44, 60, }; 在程序中如果需要动态生成这种结构性的字符串,显然后者是较为容易的,for循环中每次在遍历项的最后添加一个‘,’符号即可。而对于JSON字符串,需要添加一个判断条件语句: var strJson = '{'; for (int i = 0; i < array.length; ++i) { if (i) strJson += ','; strJson += array[i]; } 不同的浏览器实现针对这个特点有不同的实现,例如,Firefox中,默许trailing comma的存在,这对程序开发者是较为友好的。而IE7对于这个trailing comma则是非常挑剔的,算得上是有点finicky。不过既然这是标准,IE7选择了严格的语法检查,也是无可厚非的。 刚好遇到了一个bug是由于这个原因导致的,特地还安装了Visual Studio 2008来attach to process来debug dynamic scripts。因此特别记录一下。 References: 1) Introducing JSON [ ^ ] 2) Can you use a trailing comma in a JSON object? 3) Dojo ComboBox Widget (Take 2) 4) Trailing Comma Within JSON's Array