Coder Social home page Coder Social logo

Comments (4)

margox avatar margox commented on May 23, 2024

没看到Con前面的var,还以为写错了,哈哈,仔细一看,上面一行最后面还有个逗号哟

from blog.

StevenX911 avatar StevenX911 commented on May 23, 2024

// 获得构造函数,arguments中去除第一个参数
Con = [].shift.call(arguments);

"去除" 应为 "取出"

这里会给新手造成误导

from blog.

mzc9915 avatar mzc9915 commented on May 23, 2024

有个小问题,即使采用了第二版书写方式,如果在构造函数中仍然返回了一个 {name : name } , 那这个时候,实例仍无法访问原型属性,此时该怎么办呢?

from blog.

zhoushoujian avatar zhoushoujian commented on May 23, 2024

@Maozc 手动将实例化对象的__proto__关联到构造函数的prototype就可以了:

function Foo(a, b){
const obj = {}
this.a = a
obj.b = b
return obj
}
Foo.prototype.cat = function(){
console.log('qqqq')
}

var aaa = new Foo(1, 2)
aaa.proto = Foo.prototype
aaa.cat()

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.