Debug小技巧 – 为对象加入一个Object_ID Field

Categories: Development Notes; Tagged with: ; @ February 19th, 2009 23:07

使用Random来作为Field内容, 并重写toString, 便于在debug时分辨出名称相同的对象, 如:

某类: Employee: [ AS实现]:

	/**
	 * Constractor
	 */
	public function Employee(name_:String = null) {
		_name = name_;
		objectID = Math.random();
	}

//--------------------------toString-----------------

	public function toString():String {
		return name + " - " + objectID;
	}

未加id及覆盖toString前的输出信息:

[DEBUG] Controler Current Selceted Employee: [object Employee]

[DEBUG] Controler Current Selceted Employee: [object Employee]

[DEBUG] Controler Current Selceted Employee: [object Employee]

[DEBUG] Controler Current Selceted Employee: [object Employee]

加上之后:

[DEBUG] Controler Current Selceted Employee: Tom – 0.9672538451850414

[DEBUG] Controler Current Selceted Employee: Tom – 0.5573517205193639

[DEBUG] Controler Current Selceted Employee: Tom – 0.9672538451850414

[DEBUG] Controler Current Selceted Employee: Tom – 0.5573517205193639

<->



// Proudly powered by Apache, PHP, MySQL, WordPress, Bootstrap, etc,.