خرید بک لینک

Vote count: 0

This is not a dup of JSlint: unexpected 'for' , please do not mark it as such:

There is no native for loop for looping through an object or object literal ( I know there is a .forEach for arrays ).

Why does jslint suggest not using for loops? How do you loop through an object that does not have Array.forEach() or Array.some() or similar?

But the bigger more important question, is why is this suggestion made?

Obviously I could use Object.keys() and then forEach() but this seems like a longer way to do it.

Originating Code

// on a truthy match retus true and breaks from loop
Pub.someKey = function (obj, func, con) {
    var key;
    if (!Pub.isFunction(func)) {
        retu false;
    }
    for (key in obj) {
        if (obj.hasOwnProperty(key)) {
            if (func.call(con, obj[key], key, obj)) {
                retu true;
            }
        }
    }
    retu false;
};
Pub.forSomeKey = Pub.someKey;

asked 1 min ago

برچسب: نویسنده: استخدام کار تاريخ: چهارشنبه 22 ارديبهشت 1395 ساعت: 3:54

صفحه بندی