`

jQuery in action notes.

 
阅读更多

 

jQuery in action notes.

-------------------------------------
ch0. JavaScript Object fundamentals

functions are first-class objects in JavaScript

the primary purpose of an Object instance is to serve as a container for a named collection of other objects. like Map or dictionary in Java.

var shinyAndNew = new Object();
shinyAndNew.year = 2005;
need to add properties, dynamically as needed.
property access can be 2 forms:
dot operator: bith = shinyAndNew.year;
square op: birth = shinyAndNew["year"]; // shinyAndNew['year']

object literal
var shinyAndNew = {
     year: 2005,
     owner: {
          name: 'Spike Spiegel',
          occupation: 'bounty hunter'
     }
};

var shinyAndNew = {};
the same as
window.shinyAndNew = {};

an overview of the JavaScript Object:
A JavaScript object is an unordered collection of properties.
Properties consist of a name and a value.
Objects can be declared using object literals.
Top-level variables are properties of window.

Functions in JavaScript are considered objects like any of the other object types that are defined in JavaScript, such as Strings, Numbers, or Dates.
Function object can be: so it is the first-class object.
Assigned to variables
Assigned as a property of an object
Passed as a parameter
Returned as a function result
Created using literals

When we declare a top-level named function, a Function instance is created and assigned to a property of window.
the following statements are all equivalent:
function hello(){ alert('Hi there!'); }
hello = function(){ alert('Hi there!'); }
window.hello = function(){ alert('Hi there!'); }

passing functions as parameters, Functions as callbacks

the object referenced by keyword "this" — termed the function context — is determined not by how the function is declared but by how it’s invoked.

call() or apply()
We can set the function context to whatever we want by invoking a function via the Function methods call() or apply().
A function f acts as a method of object o when o serves as the function context of the invocation of f.

Closures

$(function(){
     var local = 1;
     window.setInterval(function(){
          $('#now').html('#' + local + ', ' + new Date());
          local++;
     },1000);
});
Although it is true that the block in which local is declared goes out of scope when the ready handler exits, the closure created by the declaration of the function, which includes local, stays in scope for the lifetime of the function.

Another important feature of closures is that a [function context](this object) is never included as part of the closure. but can use [outer object] to access.

a function declaration and its environment form a closure allowing the function, when later invoked, to access those local variables that become part of the closure.


-------------------------------------
ch1 Introducing jQuery

Unobtrusive JavaScript: segregate style(css), behavior(js) from structure within an HTML document.

window.onload = function() { /* do something */ };
basically equivalent to
jQuery(document).ready(function() { /* do something */ });

the same as

$(function() { /* do something */ });

but 1st one is on all resources loaded, while 2nd one only after DOM tree has loaded

In contrast, the window’s onload technique allows for only a single function.

Extending jQuery
$.fn.yourExtendedFunctionName = function() {
     //return the original set
}
分享到:
评论

相关推荐

    jquery-3.7.0.min.js(jQuery下载)

    jquery-3.7.0.min.js(jQuery下载)jquery-3.7.0.min.js(jQuery下载)jquery-3.7.0.min.js(jQuery下载)jquery-3.7.0.min.js(jQuery下载)jquery-3.7.0.min.js(jQuery下载)jquery-3.7.0.min.js(jQuery下载)...

    jquery-3.3.1.js和jquery-3.3.1.min.js

    jquery-3.3.1.js和jquery-3.3.1.min.js免费下载哈。jquery-3.3.1.js和jquery-3.3.1.min.js免费下载哈。jquery-3.3.1.js和jquery-3.3.1.min.js免费下载哈。jquery-3.3.1.js和jquery-3.3.1.min.js免费下载哈。jquery-...

    jquery.base64.js jquery-1.12.4.min.js

    本话题将详细讨论两个特定的文件:`jquery-1.12.4.min.js` 和 `jquery.base64.js`,以及它们在Web开发中的作用和相关知识点。 首先,`jquery-1.12.4.min.js` 是jQuery框架的一个版本,它是一个广泛使用的JavaScript...

    JQuery In Action.PDF

    - **Summary:** This introductory chapter provides a solid foundation for understanding the core concepts and benefits of JQuery. It prepares readers for the more advanced topics covered in subsequent ...

    jquery.zTree.js.rar

    jquery-1.4.4.min.js jquery.ztree.exhide.min.js jquery.ztree.exedit.min.js jquery.ztree.excheck.min.js jquery.ztree.core.min.js jquery.ztree.all.min.js jquery-1.4.4.js jquery.ztree.exhide.js jquery....

    开发工具 jquery.dataTables.min

    开发工具 jquery.dataTables.min开发工具 jquery.dataTables.min开发工具 jquery.dataTables.min开发工具 jquery.dataTables.min开发工具 jquery.dataTables.min开发工具 jquery.dataTables.min开发工具 jquery....

    jquery 1.12.4 .min.js 含源码

    jquery 1.12.4 .min.js 含源码 包含以下文件: jquery.1.12.4.min.js jquery.1.12.4.js // 这个是源码哦 截至2017.11.21, jQuery1.x 最新最稳定版本

    jquery.i18n.properties-min-1.0.9.js

    jquery.i18n.properties-min-1.0.9 主要用于国际化和读取properties文件

    jquery.i18n.properties.min.js

    jquery.i18n.properties.min.js

    jquery.i18n.properties-1.0.9.js

    jquery.i18n.properties-1.0.9.js 下载

    jquery-1.12.4-jquery.min.js.zip

    "jquery-1.12.4-jquery.min.js.zip"是一个包含jQuery 1.12.4精简版(minified)的压缩包,这个版本是针对生产环境优化过的,体积小但功能强大。 jQuery 1.12.4.min.js的核心特性包括: 1. **DOM操作**:jQuery ...

    开发工具 jquery-1.11.3.min

    开发工具 jquery-1.11.3.min开发工具 jquery-1.11.3.min开发工具 jquery-1.11.3.min开发工具 jquery-1.11.3.min开发工具 jquery-1.11.3.min开发工具 jquery-1.11.3.min开发工具 jquery-1.11.3.min开发工具 jquery-...

    jquery.lazyload.min.js

    jquery.lazyload.min.js插件 直接下载引入即可~~~~~~~

    jquery 1.12.4 .min.js

    jquery 1.12.4 .min.js jquery 1.12.4 .min.js jquery 1.12.4 .min.js

    jquery.i18n.properties-1.2.2.js (最新)

    jQuery.i18n.properties的API只有几个:jQuery.i18n.properties()、jQuery.i18n.prop()、jQuery.i18n.browserLang(),当然也可以采用.i18n.properties()、.i18n.properties()、.i18n.prop()、$.i18n.browserLang()的...

    jquery.jsoncookie.js

    jquery.jsoncookie.js

    jquery.lazyload.js

    《jQuery.Lazyload.js:优化网页加载速度与用户体验的艺术》 在现代网页设计中,页面加载速度和用户体验是至关重要的因素。jQuery.Lazyload.js是一个高效实用的JavaScript插件,它能够显著提升网页加载速度,同时...

    JQuery.md5.js

    JQuery.md5.js

    JQuery电影选座插件.rar

    JQuery电影选座插件.rar JQuery电影选座插件.rar JQuery电影选座插件.rar JQuery电影选座插件.rar JQuery电影选座插件.rar JQuery电影选座插件.rar JQuery电影选座插件.rar JQuery电影选座插件.rar JQuery电影选座...

    jQuery密码强度检测.rar

    jQuery密码强度检测.rar jQuery密码强度检测.rar jQuery密码强度检测.rar jQuery密码强度检测.rar jQuery密码强度检测.rar jQuery密码强度检测.rar jQuery密码强度检测.rar jQuery密码强度检测.rar jQuery密码强度...

Global site tag (gtag.js) - Google Analytics