Giter VIP home page Giter VIP logo

Comments (8)

oceanpad avatar oceanpad commented on July 21, 2024 6

ES6:

function isEmptyObject(obj){
   return Object.keys(obj).length === 0 && obj.constructor === Object
}

Pre-ECMA 5:

function isEmptyObject(obj) {
    for(var prop in obj) {
        if(obj.hasOwnProperty(prop))
            return false;
    }

    return JSON.stringify(obj) === JSON.stringify({});
}

jQuery:

jQuery.isEmptyObject({});

from frontend-interview.

RookieDay avatar RookieDay commented on July 21, 2024

@jirengu
老师 你好,第二个题目好像有点念不通,“用 ES5的方法如何来 重新函数 这个函数 ” , 不知道是不是表述有点问题。 ^_^

from frontend-interview.

Cedric-song avatar Cedric-song commented on July 21, 2024
function isEmptyObject(obj){
  if( arguments[0] && typeof arguments[0] === "object" ) {
    for ( var key in arguments[0] ) {
     return true
   }
    return false
  }
  throw "obj need to be an object"
}

from frontend-interview.

FrankFang avatar FrankFang commented on July 21, 2024

@RookieDay 已改

from frontend-interview.

Joker-Qu avatar Joker-Qu commented on July 21, 2024

function isEmptyObject(obj){
var a = {}
return JSON.stringify(obj) === JSON.stringify(a)
}

from frontend-interview.

ke1vin4real avatar ke1vin4real commented on July 21, 2024

@upfain 需要用hasOwnProperty来检测是本地属性还是原型链上的属性

from frontend-interview.

hazeFlame avatar hazeFlame commented on July 21, 2024

function isEmptyObject(obj) { if(Object.keys(obj).length){ return false }else{ return true } }

from frontend-interview.

hazeFlame avatar hazeFlame commented on July 21, 2024

function isEmptyObject(obj) {
return Object.keys(obj).length ? true : false
}

from frontend-interview.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.