V2EX = way to explore
V2EX 是一个关于分享和探索的地方
Sign Up Now
For Existing Member  Sign In
推荐关注
Meteor
JSLint - a JavaScript code quality tool
jsFiddle
D3.js
WebStorm
推荐书目
JavaScript 权威指南第 5 版
Closure: The Definitive Guide
acthtml

js prototype 中 js 指针的访问。

  •  
  •   acthtml · May 12, 2014 · 3198 views
    This topic created in 4372 days ago, the information mentioned may be changed or developed.
    function Parent(name){
    this.name = name;
    return this.init;
    }

    Parent.prototype = {
    name : '',
    init : function(){
    return this;
    }
    }

    Parent.prototype.son = {}

    ======================
    在 Parent.prototype.son 的方法中,如何访问Parent.prototype.name这个属性。
    4 replies    2014-05-12 13:54:12 +08:00
    jsonline
        1
    jsonline  
       May 12, 2014   ❤️ 1
    prototype 的属性可以看作是 Parent 的类成员。
    类成员(son)想访问另一个类成员(name)只能以类(Parent)开头了。
    jsonline
        2
    jsonline  
       May 12, 2014   ❤️ 1
    严格来说也不能算类成员……

    为什么要把一个对象放在 prototype 里呢?你的 use case 是什么?
    ldb1992
        3
    ldb1992  
       May 12, 2014   ❤️ 1
    当作静态方法访问,或者把son的原型指向parent的原型,好久没写js了,记不得了
    acthtml
        4
    acthtml  
    OP
       May 12, 2014
    感谢楼上几位的回复。

    我这种写法本身有弊端。结贴,换另一种写法。
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   2706 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 31ms · UTC 13:53 · PVG 21:53 · LAX 06:53 · JFK 09:53
    ♥ Do have faith in what you're doing.