"Class"의 두 판 사이의 차이

79번째 줄: 79번째 줄:
==같이 보기==
==같이 보기==
*[[클래스]]
*[[클래스]]
*[[Hello 클래스]]
*[[new object]]
*[[new object]]
*[[constructor]]
*[[constructor]]

2016년 1월 25일 (월) 17:39 판

  다른 뜻에 대해서는 클래스 문서를 참조하십시오.
  다른 뜻에 대해서는 typeof 문서를 참조하십시오.

1 JavaScript

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

2 PHP

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

3 Python

class One(object):
	pass
class Dog(object):
	def __init__(self, name):
		self.name = name
	def bark(self):
		print 'Woof!'

myDog = Dog('snoopy')
myDog.bark()
# Woof!

4 Ruby

class Dog
end
class Dog
  isAlive = true
end
class Dog
  def initialize(name)
    @name = name
  end
	
  def bark
    puts "Woof!"
  end
end

myDog = Dog.new("snoopy");
myDog.bark

5 같이 보기

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