返回顶部

收藏

JavaScript通过function定义对象并给对象添加toString()方法

更多
<script type="text/javascript">
function movieToString() {
   return("title: "+this.title+"  director: "+this.director);
}
function movie(title, director) {
   this.title = title;
   this.director = director;
   this.toString = movieToString; //assign function to this method pointer
}
   var aliens = new movie("Aliens","Cameron");
   document.write(aliens.toString());
</script>

标签:对象,function,toString

收藏

0人收藏

支持

0

反对

0

发表评论