evercookie(对象的调用方法)

时间:2016-06-28 06:44:33

标签: javascript php jquery function cookies

//此代码位于script.js文件中

 var E_c = (function () {

var etagCookieName = 'ecn';
var cacheCookieName = 'ccn';

  this._class = function () {

    this.set = function (name, value) {
        alert(name);
        alert(value);
    }
}; 
return this._class;});

在另一个文件中我创建了E_c的对象,但如果我尝试使用ec.set()调用set方法,则会生成错误,即ec.set()不是函数。请指导我出错了。这是我的代码

    <script type="text/javascript">

    function create_cookie() {

        var ec = new E_c();
         ec.set("id","567")  ;   

    }

        create_cookie();

1 个答案:

答案 0 :(得分:0)

 var E_c = (function () {

var etagCookieName = 'ecn';
var cacheCookieName = 'ccn';

  this._class = function () {

    this.set = function (name, value) {
        alert(name);
        alert(value);
    }
}; 
return this._class;}()); // <-- () to execute the anonymous functions