Get the reference name of an object?

后端 未结 2 1488
后悔当初
后悔当初 2020-12-22 07:04

I have an object inside another object:

function TextInput() {
    this.east = \"\";
    this.west = \"\";
}

TextInput.prototype.eastConnect = function(obje         


        
2条回答
  •  臣服心动
    2020-12-22 07:31

    puts(textInput1.east.name)
    

    This gives an undefined because JS is trying to find an object called name inside east, which does not exist. If you want to pass the name then I think you'll need to do it by passing a string. You can think about creating a property name inside east that may give its name in string. But if there are a lot of objects and you're looking for name of each then you can't go on doing this. Bad OO practice.

提交回复
热议问题