Google Closure Advanced | Object property not recognized | Dynamic Properties?

纵然是瞬间 提交于 2019-12-11 06:27:47

问题


Actual Error Code

JSC_INEXISTENT_PROPERTY

Summary

I get this error for the code listed and commented below.

I make the call like this. o_p.page holds user input and one of the properties is indeed tag

Mo.AppBAdder.image_element = vDomBMAdd(o_p.page);

o_p.page is populated by calling the object which hold user input like this:

o_p.page = text_object.getArray();

Is there a way I can do this so Google Closure does not feel the property does not exist?

Setting options is O.K. Also, I don't mind modifying the code a bit if needed.

The constructor for text reads in the user input like this:

Su.text = function (form_elements) {
    this.text_object = {};
    var key;
    for (key in form_elements) { //*u
        if (form_elements.hasOwnProperty(key)) {
            this.text_object[form_elements[key].name] = form_elements[key].value;
        }
    }
    return this;
};

Snippet of Code

function vDomBMAdd(bookmark_object) {
    var link_element = document.createElement('a'),
        image_element = document.createElement('img'),
        page_element = $a('#' + bookmark_object.tag + '_page'), // error here - inexistent property

Reference

Inexistent means same thing as nonexistent


回答1:


You have two options: create an extern file that declares the 'tag' property or, perhaps more appropriately given how the property is defined, use a quoted property access:

bookmark_object['tag']

Both of these approaches allow you to access "external" properties and are both compatible with ADVANCED optimizations but using an extern file allows you to declare the expected type of the value held by the property and thus provides better type checking.



来源:https://stackoverflow.com/questions/12254820/google-closure-advanced-object-property-not-recognized-dynamic-properties

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!