[問題] 關於自訂類別 (AS2)
最近開始練習寫自訂類別
首先先以實做分數的加減乘除開始
但是我遇到了一個問題
類別的內容大致上是
class myclass.test.test1{
private var _mother:Number;//分母
private var _son:Number;//分子
public function test1(p_s:Number, p_m:Number) {
this._mother = p_m;
this._son = p_s;
}
public function get mother():Number {
return this._mother;
}
public function get son():Number {
return this._son;
}
public function set mother(value:Number):Void {
this._mother = value;
}
public function set son(value:Number):Void {
this._son = value;
}
//加法
public function add(num:test1):test1{
this._son=this._son*num._mother+num._son*this._mother;
this._mother=this._mother*num._mother;
return this;
}
.
.
.
}
假設我在使用時
var num:test1=new test1(3,5);
當我
trace(num);
現在會出現
[object Object]
這樣的東西
但是我希望他出現的是
3/5
就像當我使用Point類別時
var pt:Point=new Point(20,50);
trace(pt);
得到的結果是
(x=20, y=50)
但是同時又不會影響到
var pt2=pt;
這樣的式子
應該要怎樣寫呢?
感恩
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 61.31.193.1
※ 編輯: no1kk 來自: 61.31.193.1 (05/13 16:52)
討論串 (同標題文章)
完整討論串 (本文為第 1 之 2 篇):