Giter Club home page Giter Club logo

Comments (4)

jjeejj avatar jjeejj commented on July 21, 2024

关于初始化空对象的方法那个:

var a = {}
var b = Object.create(null)

这两个区别是:
直接创建的a对象是默认原型继承Object对象的
创建的b对象的写法,是把b的原型修改为null

var a = {}
a.hasOwnProperty; // ƒ hasOwnProperty() { [native code] }

var b = Object.create(null)
b.hasOwnProperty; //undefined

from blog.

Aaaaaaaty avatar Aaaaaaaty commented on July 21, 2024

@jjeejj 嗯嗯是这样的,可能置空它的prototype会更快,不过我简单对比了一下直接读取这两个对象属性的时间貌似区别不大哈哈,还是不太能领会这么用的妙处233

from blog.

SirM2z avatar SirM2z commented on July 21, 2024

两种用法无关乎性能,用 var b = Object.create(null) 这种写法会更安全。

相比于 var a = {}b 对象没有原型对象,那么任何对于 this 的使用都会被限制在这个空对象中

不会对全局对象(整条原型链)产生任何影响

from blog.

Aaaaaaaty avatar Aaaaaaaty commented on July 21, 2024

@SirM2z 哦对对有道理!受教受教

from blog.

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.