Javascript 小型实用程序库正在以一种奇怪的方式运行?

Javascript 小型实用程序库正在以一种奇怪的方式运行?,javascript,Javascript,我正试图将一个小的实用程序功能添加到我的库中,这时我注意到我的实用程序库正在返回一个应用程序对象 它从一个完全不同的文件返回一个对象。我的申请是完全私人的,而且是在生活中 您可以在此处查看应用程序 www.arcmarks.com 在控制台中键入in localStorage.file_arcmarks_js $A.extend({}); 查看存储在localStorage中的应用程序文件 var CArcmarks保存的对象本身似乎已全局化,现在由实用程序函数返回 在控制台中键入in l

我正试图将一个小的实用程序功能添加到我的库中,这时我注意到我的实用程序库正在返回一个应用程序对象

它从一个完全不同的文件返回一个对象。我的申请是完全私人的,而且是在生活中

您可以在此处查看应用程序

www.arcmarks.com
在控制台中键入in

localStorage.file_arcmarks_js
$A.extend({});
查看存储在localStorage中的应用程序文件

var CArcmarks
保存的对象本身似乎已全局化,现在由实用程序函数返回

在控制台中键入in

localStorage.file_arcmarks_js
$A.extend({});
我也希望它能回来

Object { Name:CArcmarks ...
它是应用程序文件中的一个对象

Extend是一个基本的实用程序函数,它可以从一个对象复制另一个对象,如果您查看源对象,则

$A.extend
你可以看到这是一个非常简单的函数

它如何返回这个。这很奇怪

顺便说一下,这是镀铬的。我正在检查其他浏览器。。。不在FF。也许是一些奇怪的Chrome bug

我觉得我在暮色地带,有人看到了吗,或者有人给我的摩卡下了药

这里的每个注释是CArcmarks和$A.extend()的代码

在单独的文件中:

/***************************************************************************************************
**CArcmarks
*/

    var CArcmarks = $A.Class.create({
        Name: 'CArcmarks',
        A: {
            toggle_page_lazy:           'toggle_page_lazy',
            toggle_page_active:         'toggle_page_active',
            toggle_tag_active:          'toggle_tag_active',
            toggle_tag_lazy:            'toggle_tag_lazy'
        },
        render: function (obj, el) {

            // element to render into is passed and a ns is extracted from the id
            // from this additional elements are extracted
            this.el = el;
            this.ns = el.id + '_';
            this.el_arcmarks = $A.el('#' + el.id + '_arcmarks');
            this.el_tags = $A.el('#' + el.id + '_tags');

            // holds data from the server to be inserted into template
            this.obj = obj;
            this.tags = {};
            this.composePane();
        },
        composePane: function () {

            // abstract out a page_string so the HTML is not tangled in the JavaScript
            var //favorite_string = '',
                tag_string = '',
                page_string = '',
                current_id,
                previous_id;
            _.each(this.obj, function (val) {
                previous_id = current_id;
                current_id = this.ns + val.tag;

                // a new tag has been found, create page and tag
                if ((previous_id !== current_id) || (previous_id === undefined)) {
                    this.tags[current_id] = '';
                    tag_string += this.composeTag(current_id);
                    page_string += this.composePage(current_id);

                    /*
                    if (previous_id !== undefined) {
                        favorite_string += '</div>';
                    }
                    favorite_string += this.composePage(current_id);
                    */
                }
                this.tags[current_id] += this.composeFavorite(val);
                // favorite_string += this.composeFavorite(val);
            }, this);

            // favorite_string = favorite_string + '</div>';
            if (!_.isEmpty(this.tags)) {
                this.el_arcmarks.innerHTML = page_string;
                // this.el_arcmarks.innerHTML = favorite_string;
                this.el_tags.innerHTML = tag_string;
                this.insertFavorites();
                this.initPane();
            }
        },
        insertFavorites: function () {
            $A.someChild(this.el_arcmarks, function (val) {
                if (val.id) {
                    val.innerHTML = this.tags[val.id.slice(0,-5)];
                }
            }, this);
        },
        composePage: function (current_id) {
            return _.template($('#item-page').html(), {
                foo: current_id + '_page'
            });
        },
        composeFavorite: function (val) {
            return _.template($('#item-arcmark').html(), {
                id:    this.ns + val.id,
                ida:   this.ns + val.id + 'a',
                idb:   this.ns + val.id + 'b',
                src:   val.favicon !== null ? val.favicon : 'http://arcmarks.com/arcmarks/images/image_null_50.png',
                href:  val.url,
                title: val.title
            });
        },
        composeTag: function (current_id) {
            var self = this;
            return _.template($('#item-tag').html(), {
                id:   current_id,
                foo:  current_id.slice(self.ns.length)
            });
        },
        initPane: function () {
            var self = this;
            _.each(this.tags, function (val, key) {
                $A.el('#' + key).addEventListener("click", function () {
                    self.flip(this);
                });
            }, this);
            this.flip($A.el('#' + $A.firstKey(this.tags)));
        },
        flip: function (tag_element) {
            var page_element = $A.el('#' + tag_element.id + '_page');

            // turn current page/tag on
            $A.toggleClass(page_element, this.A.toggle_page_active);
            $A.toggleClass(tag_element, this.A.toggle_tag_active);

            // turn off previous page/tag if it exists and it is not also the current
            if (this.prev_page_el && (tag_element.id !== this.prev_tag_el.id)) {
                $A.toggleClass(this.prev_page_el, this.A.toggle_page_lazy);
                $A.toggleClass(this.prev_tag_el, this.A.toggle_tag_lazy);
            }
            this.prev_page_el = page_element;
            this.prev_tag_el = tag_element;
        },
        insertFavorite: function (obj_fav) {
            var tag_id = this.ns + obj_fav.tag,
                div_el,
                html_string = this.composeFavorite(obj_fav),
                page_el = $A.el('#' + tag_id + '_page');
            div_el = $A.HTMLToElement(html_string);
            if (!page_el) {
                page_el = this.insertTagAndPage(tag_id);
            }
            $A.someChild(page_el, function (iter) {
                if (iter === null) {
                    page_el.appendChild(div_el);
                    return true;
                }
                if (obj_fav.title < iter.children[1].innerHTML) {
                    page_el.insertBefore(div_el, iter);
                    return true;
                }
                if (iter === page_el.lastChild) {
                    page_el.appendChild(div_el);
                    return true;
                }
            });
            this.flip($A.el('#' + tag_id));
            return div_el;
        },
        insertTagAndPage: function (tag) {
            var par_el,
                div_el,
                hold_tags_el,
                hold_arcmarks_el,
                self = this;
            hold_tags_el = this.el_tags;
            hold_arcmarks_el = this.el_arcmarks;
            par_el = $A.createElement('p');

            // update this
            par_el.innerHTML = tag.slice(this.ns.length);
            par_el.className = "single_tag";
            par_el.id = tag;

            // insert the tag(<p>)
            $A.someChild(hold_tags_el, function (iter) {
                if (iter === null) {
                    hold_tags_el.appendChild(par_el);
                    return true;
                }
                if (par_el.id < iter.id) {
                    hold_tags_el.insertBefore(par_el, iter);
                    return true;
                }
                if (iter === hold_tags_el.lastChild) {
                    hold_tags_el.appendChild(par_el);
                    return true;
                }
            });
            par_el.addEventListener("click", function () {
                self.flip(this);
            });
            div_el = $A.createElement('div');
            div_el.className = "bookmark_page";
            div_el.id = tag + "_page";
            div_el.style.display = "";
            $A.someChild(hold_arcmarks_el, function (iter) {
                if (iter === null) {
                    hold_arcmarks_el.appendChild(div_el);
                    return true;
                }
                if (div_el.id < iter.id) {
                    hold_arcmarks_el.insertBefore(div_el, iter);
                    return true;
                }
                if (iter === hold_arcmarks_el.lastChild) {
                    hold_arcmarks_el.appendChild(div_el);
                    return true;
                }
            });
            return div_el;
        }
    }, 'constructor');
/***************************************************************************************************
**汽车标志
*/
var CArcmarks=$A.Class.create({
名称:'CArcmarks',
A:{
toggle_page_lazy:“toggle_page_lazy”,
切换页面处于活动状态:“切换页面处于活动状态”,
toggle_tag_active:“toggle_tag_active”,
toggle_tag_lazy:“toggle_tag_lazy”
},
渲染:函数(obj、el){
//传递要渲染到的元素,并从id中提取ns
//从中提取其他元素
this.el=el;
this.ns=el.id+'';
this.el_arcmarks=$A.el(“#”+el.id+“_arcmarks”);
this.el_tags=$A.el('#'+el.id+'_tags');
//保存服务器中要插入到模板中的数据
this.obj=obj;
this.tags={};
这个是composePane();
},
composePane:函数(){
//抽象出一个页面字符串,这样HTML就不会与JavaScript纠缠在一起
var//favorite_字符串=“”,
标记字符串=“”,
第_页字符串=“”,
当前用户id,
以前的身份证;
_.each(this.obj,function(val){
上一个\u id=当前\u id;
当前_id=this.ns+val.tag;
//已找到新标记,请创建页面和标记
if((上一个_id!==当前_id)| |(上一个_id==未定义)){
this.tags[current_id]='';
tag_string+=this.composeTag(当前_id);
page_string+=此.composePage(当前_id);
/*
如果(上一个_id!==未定义){
收藏夹_字符串+='';
}
收藏夹\u字符串+=此.composePage(当前\u id);
*/
}
this.tags[current_id]+=this.composeFavorite(val);
//favorite_string+=此.composeFavorite(val);
},这个);
//收藏夹字符串=收藏夹字符串+“”;
if(!\u.isEmpty(this.tags)){
this.el_arcmarks.innerHTML=页面字符串;
//this.el_arcmarks.innerHTML=收藏夹字符串;
this.el_tags.innerHTML=标记字符串;
这个.insertFavorites();
this.initPane();
}
},
insertFavorites:函数(){
$A.someChild(this.el_arcmarks,function(val){
如果(val.id){
val.innerHTML=this.tags[val.id.slice(0,-5)];
}
},这个);
},
composePage:函数(当前\u id){
返回35;.template($('#项目页').html(){
foo:当前_id+“_页面”
});
},
composeFavorite:函数(val){
返回35;.template($('#item arcmark').html(){
id:this.ns+val.id,
艾达:this.ns+val.id+a,
idb:this.ns+val.id+b',
src:val.favicon!==null?val.favicon:'http://arcmarks.com/arcmarks/images/image_null_50.png',
href:val.url,
标题:val.title
});
},
composeTag:函数(当前\u id){
var self=这个;
返回35;.template($('#项标记')).html(){
id:当前的\u id,
foo:current_id.slice(self.ns.length)
});
},
initPane:函数(){
var self=这个;
_.each(this.tags,function(val,key){
$A.el(“#”+键)。添加EventListener(“单击”,函数(){
翻转(这个);
});
},这个);
this.flip($A.el('#'+$A.firstKey(this.tags));
},
翻转:功能(标记元素){
var page_element=$A.el('#'+tag_element.id+'_page');
//打开当前页面/标记
$A.toggleClass(页面元素,此.A.toggle页面处于活动状态);
$A.toggleClass(标记元素,此.A.toggle标记活动);
//如果上一页/标记存在且不是当前页/标记,请关闭该页/标记
if(this.prev_page_el&(tag_element.id!==this.prev_tag_el.id)){
$A.toggleClass(this.prev\u page\u el,this.A.toggle\u page\u lazy);
$A.toggleClass(this.prev\u tag\u el,this.A.toggle\u tag\u lazy);
}
this.prev_page_el=页面元素;
this.prev_tag_el=tag_元素;
},
insertFavorite:函数(obj_fav){
var tag_id=this.ns+obj_fav.tag,