Skip to content

Attributes typeof 'function' or 'object' #13

@godtail

Description

@godtail

Description

Typeof function

When I use a attribute name 'link' like this {{ item.link }}, and passed a object { item:[] }, after parse it returns a function like this: function (a){for(var b={},c=0,d=this.length;c<d;c++)for(var e in a)if(a[e](this[c])){b[e]=this[c];delete a[e];break}return b}.

The link function is generation by mootools(item is an Array, and mootools changed the Array.prototype).

So, I need avoid to use link or other special attributes, It's cost a lot of time to check. but for another scene, useful for bind func on onclick.

<button onclick="{{ item.clickFunc }}"></button>

Type of object

For special scene, It's need return the encoded JSON.

<ul class="menu" data-setting="{{ menu.setting }}"></ul>

Now, only for the TextNode.

// parseTextNode
if (node.nodeType === (node.TEXT_NODE || 3)) {
       node.nodeValue = node.nodeValue.replace(VALUE_OUT_REG, (item, $1) => {
               var value = this.parseSodaExpression($1, scope);
               if (typeof value === "object") {
                     value = JSON.stringify(value, null, 2)
                }
                return value;
       });
}

Suggest

From src/soda.js, _getValue function

if (typeof data[attrStr] !== "undefined") {
    rValue = data[attrStr];
}

Ideas

Just ideas, need discuss.

  1. We always focus on the passed objects(sodaScope), and don't care with the attributes on there prototype, add hasOwnProperty to check attributes.

  2. check the element attributes name like 'onclick', bad way!!!

  3. typeof object, use JSON.stringify.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions