JS方法里面没有加return,就出错了?

ReadCookie_sns = function(){   ReadCookie("myname"); }

出错,提示:Unexpected token u in JSON at position 0

改为:

ReadCookie_sns = function(){ return  ReadCookie("myname"); }

好了。 加了return, 就好了。请问为什么?

-----------------下面是ReadCookie方法。

ReadCookie = function(cookieName) {

        var theCookie = "" + document.cookie;

        var ind = theCookie.indexOf(cookieName);

        if (ind == -1 || cookieName == "") return "";

        var ind1 = theCookie.indexOf(';', ind);

        if (ind1 == -1) ind1 = theCookie.length;

        /*读取Cookie值*/

        return unescape(theCookie.substring(ind + cookieName.length + 1, ind1));

    }


胡说叔叔
浏览 508回答 1
1回答
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

JavaScript