外部插件:
$.fn.tinytip = function(text, customoptions) {
debugger;
if (text && typeof text === 'object'){
customoptions = text;
text = customoptions.tooltip;
}
var options = $.extend({}, tooltip_options, customoptions);
options.tooltip = text;
if (typeof options.tooltip === 'object'){
options.content = options.tooltip;
options.content.hide();
。。。。。。
。。。。
由jquery源碼而起
jquery.extend = jquery.fn.extend = function() {
var options, name, src, copy, copyisarray, clone,
target = arguments[0] || {},
i = 1,
length = arguments.length,
deep = false;
// handle a deep copy situation
if ( typeof target === "boolean" ) {
deep = target;
target = arguments[1] || {};
// skip the boolean and the target
i = 2;
}
// handle case when target is a string or something (possible in deep copy)
if ( typeof target !== "object" && !jquery.isfunction(target) ) {
target = {};
// extend jquery itself if only one argument is passed
if ( length === i ) {
target = this;
--i;
。。。。。
1、在javascript中,arguments對象是比較特别的一個對象,實際上是目前函數的一個内置屬性。arguments非常類似array,但實際上又不是一個array執行個體。可以通過如下代碼得以證明(當然,實際上,在函數funcarg中,調用arguments是不必要寫成funcarg.arguments,直接寫arguments即可)。
array.prototype.testarg = "test";
function funcarg() {
console.log(funcarg.arguments.testarg);
console.log(funcarg.arguments[0]);
console.log(arguments[0]);
}s
console.log(new array().testarg); // result: "test"
funcarg(10); // result: "undefined" "10"
2、arguments對象的長度是由實參個數而不是形參個數決定的。形參是函數内部重新開辟記憶體空間存儲的變量,但是其與arguments對象記憶體空間并不重疊。對于arguments和值都存在的情況下,兩者值是同步的,但是針對其中一個無值的情況下,對于此無值的情形值不會得以同步。如下代碼可以得以驗證。
function f(a, b, c){
console.log(arguments.length); // result: "2"
a = 100;
console.log(arguments[0]); // result: "100"
arguments[0] = "qqyumidi";
console.log(a); // result: "qqyumidi"
console.log(c); // result: "undefined"
c = 2012;
console.log(arguments[2]); // result: "undefined"
f(1, 2);
3、由javascript中函數的聲明和調用特性,可以看出javascript中函數是不能重載的。根據其他語言中重載的依據:"函數傳回值不同或形參個數不同",我們可以得出上述結論:
第一:javascript函數的聲明是沒有傳回值類型這一說法的;
第二:javascript中形參的個數嚴格意義上來講隻是為了友善在函數中的變量操作,實際上實參已經存儲在arguments對象中了。
另外,從javascript函數本身深入了解為什麼javascript中函數是不能重載的:在javascript中,函數其實也是對象,函數名是關于函數的引用,或者說函數名本身就是變量。對于如下所示的函數聲明與函數表達式,其實含以上是一樣的(在不考慮函數聲明與函數表達式差別的前提下),非常有利于我們了解javascript中函數是不能重載的這一特性。
function f(a){
return a + 10;
return a - 10;
// 在不考慮函數聲明與函數表達式差別的前提下,其等價于如下
var f = function(a){
4、arguments對象中有一個非常有用的屬性:callee。arguments.callee傳回此arguments對象所在的目前函數引用。在使用函數遞歸調用時推薦使用arguments.callee代替函數名本身。
function count(a){
debugger;
if(a==1){
return 1;
}
return a + arguments.callee(--a);
var mm = count(10);
console.log(mm); //55