×

Loading...
Ad by
  • 最优利率和cashback可以申请特批,好信用好收入offer更好。请点链接扫码加微信咨询,Scotiabank -- Nick Zhang 6478812600。
Ad by
  • 最优利率和cashback可以申请特批,好信用好收入offer更好。请点链接扫码加微信咨询,Scotiabank -- Nick Zhang 6478812600。

狗来的

This is made because the undefined global property in ECMAScript 3, is mutable, meaning that someone could change its value affecting your code, for example:

undefined = true; // mutable
(function (undefined) {
alert(typeof undefined); // "undefined", the local identifier
})(); // <-- no value passed, undefined by default

If you look carefully undefined is actually not being passed (there's no argument on the function call), that's one of the reliable ways to get the undefined value, without using the property window.undefined.

The name undefined in JavaScript doesn't mean anything special, is not a keyword like true, false, etc..., it's just an identifier.

Just for the record, in ECMAScript 5, this property was made non-writable...
Report

Replies, comments and Discussions:

  • 工作学习 / 学科技术讨论 / JQuery的plugin, function($,undefined)中的undefined是啥意图啊?
    本文发表在 rolia.net 枫下论坛(function($,undefined){
    $.fn.myFlashMessage = function(params) {
    //use extend to merge input parameters and defaults.
    //use an empty object literal first as it is
    //overwritten by the extend method.
    var settings = $.extend(
    {},
    {
    levelClass : 'info',
    animationSpeed : 1000
    },
    params);
    if(typeof(settings.message) === 'string') {
    //our jQuery object
    this
    //replace html with the message
    .html(settings.message)
    //add the appropriate class for the message level
    .addClass(settings.levelClass)
    //click to close the message.
    //remove the handler once it has run.
    .one('click',function(){
    $(this)
    .slideUp(settings.animationSpeed, function(){
    //this will remove the Class once
    //slideUp is complete
    $(this).removeClass(settings.levelClass);
    });
    })
    .slideDown(settings.animationSpeed);
    }
    }
    })(jQuery);更多精彩文章及讨论,请光临枫下论坛 rolia.net
    • 看了懂JQuery的还是不多啊。
      • 不好意思答
    • typo。扫了一眼,一堆代码,也没格式,说的不一定对:你把它删了,应该也不影响功能。如果有不同,请上来报一声。
      • 现在比的是谁写的花, 不是能否实现功能的问题。
        • library 的 code,很多是为了保险 (safety),不是为了花。
    • 狗来的
      This is made because the undefined global property in ECMAScript 3, is mutable, meaning that someone could change its value affecting your code, for example:

      undefined = true; // mutable
      (function (undefined) {
      alert(typeof undefined); // "undefined", the local identifier
      })(); // <-- no value passed, undefined by default

      If you look carefully undefined is actually not being passed (there's no argument on the function call), that's one of the reliable ways to get the undefined value, without using the property window.undefined.

      The name undefined in JavaScript doesn't mean anything special, is not a keyword like true, false, etc..., it's just an identifier.

      Just for the record, in ECMAScript 5, this property was made non-writable...
      • 估计LZ给的代码的作者也是这样,狗了狗,抄了抄,知其然,不知其所以然的乱用。结果,看代码,维护代码的LZ就傻眼了。
        简单的说,如果是你找出的这个原因(reset undefined) 的话, 这个参数是没有必要的,LZ的函数里没有用到undefined

        大多数情况下,没有必要直接用undefined,也就是

        var_a !== undefined

        而是,应该用下面的方法

        typeof var_a !== "undefined"

    • The code creates a function without a name (not polluting the global space), and then immediately executes it.
      There are a few reasons to use this pattern. In our case, we use the function so the we can use the ‘$’ to mean ‘jQuery’, even if the ‘$’ variable is assigned to something else outside of this function. We also have a parameter ‘undefined’. Although we aren’t yet using ‘undefined’ in code yet I’ve added it for future revisions. Adding ‘undefined’ (yet passing in nothing as the parameter when executing the function) allows us to make sure someone didn’t do this sort of funny business in javascript previous to our function execution
      • As I said, it is useless in current version, right?