Constructor

클래스 생성자
__construct

1 JavaScript[편집]

function Dog(name) {
  this.name = name;
}
var myDog = new Dog("snoopy");
console.log(myDog.name);
// snoopy

2 PHP[편집]

class Dog {
  public $name;
  public function __construct($name) {
    $this->name = $name;
  }
}
$myDog = new Dog("snoopy");
echo $myDog->name;
// snoopy

3 Python[편집]

class Dog(object):
	def __init__(self, name):
		super(Dog, self).__init__()
		self.name = name

mydog = Dog("snoopy")
print mydog.name
# snoopy

4 Ruby[편집]

class Dog
  def initialize(name)
    @name = name
  end
end

myDog = Dog.new("snoopy")

5 같이 보기[편집]

문서 댓글 ({{ doc_comments.length }})
{{ comment.name }} {{ comment.created | snstime }}