若干JS框架杂谈

近来利用一点时间,对十多个 JavaScript 框架进行感性的认识,谈不上知性、理性、超越理性、悟性,因为本人真的没在项目中使用过这些 JS 框架,顶多按自己的理解在源码中发掘一下上下文的意思。然而另外一点必须唠叨,对 JS 的悟性却是无止境的……多看看人家心血作品总该有益的。言归正传,究竟我想干什么呢?就是围绕一些 JS 框架的个人评价,可能不入大家法眼,请多体察。


LivePipe

LivePipe™  http://livepipe.net/采用 prototype.js 作为底层库,提供一系列的基础控件如 tab、window 等。其标榜的“面向事件编程”,带来优点之一就是源码可读性强,并且易于扩展。不过作为一个基本的控件库,考虑得地方不算多,例如 setCookie() 的函数明显就“偷工减料”。p.s 这个库的图片素材很赞。

BlueShoes

BlueShoes 提供很多 JS 小物件的设计www.blueshoes.org/en/javascript/。界面上没有出彩的地方,采用经典凹凸边框。放眼源码都是一个个 funciotn,而且对象 {} 的写法都很少见。其源码尤其令人吃惊的地方底层从 Netscape Navigator 4.0 和 IE4 开始支持的(EventHandler.js)。看来,综合界面和源码遇到了前辈了。

CSSUtilities

看 CSSUtilities 源码是一个很舒服的事情(http://t.cn/a9TWZ0)。不是俺矫情,而是它附带的注释确是详尽,生怕你不懂似的(仍要加强英语:)。此乃归功于作者 James Edwards 杰出的贡献,但若说和 John 的 Sizzle.js 速度比起来怎么,俺就和你一样不知道,呵。浏览 James 优雅的主页,还有其他好东西,GoGo!

flashblockdetector

Flash 很“不幸地”成为众多广告的载体,为防止烦人的广告出现于是出现了很多的拦截 Flash 插件。但我们怎么知道浏览器有否安装这些插件呢?通过 JS 脚本可以侦查出插件,比如要介绍的这个 flashblockdetector。顾名思义,它仅仅只是检测,而不是使那些拦截器失去作用。其实,如用好这个插件,用户却会遭殃的……

Spine

客户端 MVC 的框架越来越多了,Spine( maccman.github.com/spine)即是一例。Spine 与 Backbone 很像,参考了后者许多接口,一般没什么问题,Routing/Patterns 也一应俱全,还有 guid 函数。该库有自己的 OO 机制(试问哪个库没有?),为 D.C 那套再扩充。Event 方面仍是大路的事件队列。代码小而精应该可以和 BackB 比一比。

Underscore

Underscore( http://documentcloud.github.com/underscore/)可谓博众家之所长,计有 prototype 和 JohnResig、尤其 FP 大牛 OliverSteele 等。撇开 FP 特性不谈,看自己懂的且有意思的地方:类型检查,看对象是否有某方法为准,如''应有 charCodeAt 等,我自己编码时就常用 pop 测数组。自己受教育的就是,检查布尔类型,简单得令人豁然开朗,obj===true||obj===false

json-sans-eval

标准方法 JSON.parse 未普及之前,eval 仍是解析 json 字符的主要手段。但因为通过 eval,所以欠缺安全性方面的考虑,容易免恶意代码借此入侵。针对此问题于是有了规避 eval 的方法,如 json_parse.js(安全却效率低)/json2.js(快,牺牲了安全性),还有 http://code.google.com/p/json-sans-eval/,应该有不少改善。

BBC glow

浏览 BBC 公司出品的 JS 框架 Glow 之源码中,发现绝非大路货( http://www.bbc.co.uk/glow/)。优点:一、对程序员友好,表现在完善的错误检查,看看 util.cookie() 就知道了;二、优良的模块组织,通过 Glow.provide 定义模块;三、整合速度著称的 Sizzle;四、详尽的文档例子;五、一些灵活的技巧,如 nArr=[0,NaN];(/…/.exec(ua)||nArr)[1]

wu.js

刚搜索下,竟没有关于 wu.js 像样的介绍。wu 和前面介绍的 underscore 那样,也是搞 FP、惰性计算为主的 js 库(http://fitzgen.github.com/wu.js/),浏览器和 node 里面皆可使用。迭代器 Iterators 是 wu 里的大头,什么惰性计算?又关迭代器神马事情?该库首页第一个例子便开明宗义解答这俩个问题,十分友好。另高阶 fn 也是重点。wu 很有个性名字上可看出。

Google Closure-pools.js

顺瓜摸藤来到 Google Closure 宝地,发现其事件库很周详,连对象池 pools.js 都有,其他的更别说了,Gog 正是艺高人胆大什么的包罗万有。瞧瞧这对象池( http://closure-library.googlecod ... vents_pools.js.html),不说什么作用光看语法,有一个特色就是某一个成员既不分配值,也不作任何运算,后面加个分号;就完了—什么意思?估计乃“签名”而已,后面代码再详细定义。

p.s关于Google Closure,笔者翻译过它对 Ext JS 比较的文章,可参考JS堂帖子

Oz.js

“短小精悍、跨浏览器、完全面向对象……"但凡js库的这些,我们都听得太多,再不就是文档、例子的考量。实际上做一个 js 库不难,js 本身也上手容易,脚本还是脚本很利于练手,有激情马上可以做,而且做出的库每个都可以说 yet anotherjsLib 云云。作为收录我把这定为一类,以 Oz 为代表 http://code.google.com/p/oz-js/

Beyond.JS

BeyondJS 作为一个典型的函数式风格 js 库,早在 05 年左右面世。有朋友或许还记得 w3future 这个网站,她很早对 js FP 方面进行发掘,提到的例子就是一行 curry 搞定的。源码看起来可能有点陈旧的味道,用 eval() 也比较多,但有一个好玩的地方在于支持 rhinoh 和微软的 HTA/WSF 组件——难道要证明 FP 走遍天下 js 宿主?

Backbone.js

群友谈到,Backbone.js 做 MVC 很好http://documentcloud.github.com/backbone/,仔细瞧瞧源码,它分配 Collection 成员方法有一套,把方法名称的字符串放置一数组,然后遍历继而 apply:_[method].apply(_,[this.models].concat(_.toArray(arguments))); 虽然比较繁琐,但仍感觉作者一气呵成写出来的包括丰富的注释内容,呵呵。

mustache.js

mustache.js https://github.com/raycmorgan/Mu,作为一款健壮的模板系统,可支持包括 node 在内的 ruby、coffeescript 等众多语言。群内已有勇于尝试 mustcha 朋友,投入到一个论坛项目中,全程 js! http://www.iwillwen.com/microgroup.html。mustache 支持编译模板,这和小弟在 ExtJS 上了解的模板编译有何不同呢?哪个快?~要待好奇的我去瞄瞄。

---------------------------END---------------------------

提到的 js 框架有些已经没有官方网站了,可以在JS堂下载源码。

一边继续关注“可爱”的 JS 框架,一边继续补充吧……



  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 4
    评论
Beyond jQuery gives you the confidence to abandon your jQuery crutches and walk freely with the power of the "web API" and JavaScript! Learn about the most important concepts surrounding web development as the mystic powers of jQuery are explained, allowing you to forgo this seemingly quintessential library in your software projects. Beyond jQuery doesn't just throw code at you - everything is explained in detail from the perspective of a jQuery developer. jQuery is often injected into web applications and libraries without any real thought, seemingly out of habit or fear. Many web developers don't seem to know exactly when they need to use jQuery, and when they don't - it has become a standard step for many when setting up a new library or web application. But relying solely on jQuery as your window to the web leaves large gaps in your knowledge. This in turn results in frustration when the abstraction that jQuery provides "leaks" and exposes you to the native aspects of the browser. This book aims to educate you and help you solve common problems without depending on jQuery. It will give you more confidence to embrace the power of the web API and standardized JavaScript. Along the way, you'll discover why it is so important to gain a solid understanding of the underpinnings of the web. This book includes chapters on DOM manipulation, data storage and retrieval, styling and CSS, AJAX requests, events, asynchronous operations, and much more. Cutting edge web and JavaScript specifications, such as the Fetch API, Promises, WeakMap, and Async Functions, are also discussed. Check out the comprehensive web application at github.com/Beyond-jQuery/exercise which was developed for "Beyond jQuery" readers that covers many of the concepts discussed in this book. Table of Contents Chapter 1: The Oppressive Magic of jQuery Chapter 2: You Don’t Need jQuery (Anymore) Chapter 3: Understanding the Web API and “Vanilla” JavaScript Chapter 4: Finding HTML Elements Chapter 5: Using and Understanding HTML Element Attributes Chapter 6: HTML Element Data Storage and Retrieval Chapter 7: Styling Elements Chapter 8: DOM Manipulation Chapter 9: AJAX Requests: Dynamic Data and Page Updates Chapter 10: Browser Events Chapter 11: Mastering Asynchronous Tasks Chapter 12: Common JavaScript Utility Functions Chapter 13: Going Forward
Beyond jQuery gives you the confidence to abandon your jQuery crutches and walk freely with the power of the “web API” and JavaScript! Learn about the most important concepts surrounding web development as the mystic powers of jQuery are explained, allowing you to forgo this seemingly quintessential library in your software projects. Beyond jQuery doesn’t just throw code at you – everything is explained in detail from the perspective of a jQuery developer. jQuery is often injected into web applications and libraries without any real thought, seemingly out of habit or fear. Many web developers don’t seem to know exactly when they need to use jQuery, and when they don’t – it has become a standard step for many when setting up a new library or web application. But relying solely on jQuery as your window to the web leaves large gaps in your knowledge. This in turn results in frustration when the abstraction that jQuery provides “leaks” and exposes you to the native aspects of the browser. This book aims to educate you and help you solve common problems without depending on jQuery. It will give you more confidence to embrace the power of the web API and standardized JavaScript. Along the way, you’ll discover why it is so important to gain a solid understanding of the underpinnings of the web. This book includes chapters on DOM manipulation, data storage and retrieval, styling and CSS, AJAX requests, events, asynchronous operations, and much more. Cutting edge web and JavaScript specifications, such as the Fetch API, Promises, WeakMap, and Async Functions, are also discussed. Check out the comprehensive web application at github.com/Beyond-jQuery/exercise which was developed for “Beyond jQuery” readers that covers many of the concepts discussed in this book.
在Java中,可以使用NI-VISA库来进行GPIB接口控制,下面是一个简单的示例代码。 ```java import com.sun.jna.Native; import com.sun.jna.Pointer; import com.sun.jna.ptr.IntByReference; import visa32.*; public class GPIBControl { private static final int GPIB_ADDRESS = 1; // GPIB地址 private static final int BUFFER_SIZE = 1024; // 缓冲区大小 public static void main(String[] args) { // 初始化NI-VISA库 VisaLibrary visaLibrary = (VisaLibrary) Native.loadLibrary("visa32", VisaLibrary.class); visaLibrary.viOpenDefaultRM(); // 打开GPIB设备 String deviceName = "GPIB0::" + GPIB_ADDRESS + "::INSTR"; Pointer instrument = new Memory(GpibLibrary.ViUInt32.SIZE); visaLibrary.viOpen(visaLibrary.getResourceManager(), deviceName, new GpibLibrary.ViAccessMode(GpibLibrary.VI_NO_LOCK), new GpibLibrary.ViUInt32(0), instrument); Pointer session = instrument.getPointer(0); // 设置超时时间 visaLibrary.viSetAttribute(new GpibLibrary.ViSession(session), new GpibLibrary.ViAttrState(GpibLibrary.VI_TMO_VALUE), new GpibLibrary.ViUInt32(5000)); // 写入命令 String command = "*IDN?"; visaLibrary.viWrite(new GpibLibrary.ViSession(session), command.getBytes(), new GpibLibrary.ViUInt32(command.length()), new IntByReference()); // 读取响应 byte[] buffer = new byte[BUFFER_SIZE]; visaLibrary.viRead(new GpibLibrary.ViSession(session), buffer, new GpibLibrary.ViUInt32(BUFFER_SIZE), new IntByReference()); String response = new String(buffer).trim(); System.out.println("Instrument response: " + response); // 关闭设备 visaLibrary.viClose(new GpibLibrary.ViSession(session)); visaLibrary.viClose(visaLibrary.getResourceManager()); } } ``` 这个示例代码使用NI-VISA库来打开GPIB设备,设置超时时间,写入命令并读取响应。需要注意的是,GPIB_ADDRESS变量需要设置为实际的GPIB地址,BUFFER_SIZE变量可以根据需要进行调整。 在实际应用中,需要根据仪器的通信协议进行编写代码,例如使用SCPI命令进行控制。希望这个示例代码能够对你有所帮助!

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

sp42a

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值