所以總會理所當然的將json一視同仁,
但....
JSON的引號只能用"
勿用了' 就會搞死自已啊!!!!
附帶一提:
總算撥雲見日的第六屆華文部落格大獎入圍名單出爐囉!
每個人都很單純,大家都是夥伴。
cd=console.debug;
function Component(base)
{
this.base=null;
try{
this.base=base;
}catch(e){}
this.name="";
this.value=0;
this.getDes=function(){
var s='';
try{
s+=this.base.getDes();
}catch(e){}
s+=this.name+','
return s;
}
this.cost=function(){
var v=0;
try{
v+=this.base.cost();
}catch(e){}
v+=this.value;
return v;
}
}
/*inherit*/
function Espresso(base)
{
var d=new Component(base);
d.name="Espresso";
d.value=100;
return d;
};
function Mocha(base)
{
var d=new Component(base);
d.name="Mocha";
d.value=10;
return d;
};
function Soy(base)
{
var d=new Component(base);
d.name="Soy";
d.value=50;
return d;
};
(function(){
var e= new Espresso(),
m= new Mocha(e),
a= new Mocha(m),
s= new Soy(a);
cd(s.cost());
cd(s.getDes());
})();
class Component():
base=None
name=''
value=0
def __init__(self,base=None):
try:
self.base=base
except:
pass
def getDes(self):
s=''
try:
s+=self.base.getDes()+','
except:
pass
s+=self.name
return s
def cost(self):
v=0;
try:
v+=self.base.value
except:
pass
return v+self.value
class Espresso(Component):
name='Espresso'
value=2000
pass
class Soy(Component):
name='Soy'
value=20
pass
class Mocha(Component):
name='Mocha'
value=200
pass
def main():
s=Espresso()
s=Mocha(s)
s=Mocha(s)
s=Soy(s)
st=s.getDes()
v=s.cost()
print st
print v
if __name__!='__main__':
main()
import sys
import os
################### BASIC CLASS begin ##############
class Subject():
name='Subject'
def __init__(self,name):
self.name=name
#
parms={}
def setTemp(self,parms):
self.parms=parms
self.notify()
#for observer
objs=[]
def register(self,obj):
self.objs.append(obj)
def remove(self,obj):
self.objs.remove(obj)
def notify(self):
for i in self.objs:
print i
i.update(self,self.parms)
class Observer():
name='Observer'
def __init__(self,name):
self.name=name
def update(subject,self,parms):
print 'Subject Name: %s,Observer Name : %s ,Value: %i'%(subject.name,self.name, parms['value'])
pass
def display(self):
pass
################### BASIC CLASS end ##############
class Weather(Subject):
pass
class Board(Observer):
value=0
def update(self,parms):
self.value=parms['value']
self.display()
def display(self):
print self.value
class Combine(Subject,Observer):
pass
def main():
s=Weather('Weather')
b=Combine('Board')
s.register(b)
s.setTemp({'value':99})
if __name__!='__main__':
main()
cd=console.debug
function Subject()
{
this.name='Subject';
this.parms={};
this.setTemp=function(parms){
this.parms=parms;
this.notify()
}
//
this.objs=new Array();
this.register=function(obj){
this.objs.push(obj);
}
this.remove=function(obj){
}
this.notify=function(){
for (i in this.objs){
this.objs[i].update(this.parms)
}
}
}
function Observer()
{
this.name='Observer';
this.update=function(parms){
this.display(parms);
}
this.display=function(parms){
cd(parms);
}
}
//set different class over there
function Weather()
{
var father=new Subject();
father.name='Weather';
return father;
}
function Board(){
var father=new Observer();
father.name='Board';
father.display=function(parms){
cd('Value:'+parms['value'])
}
return father;
}
function main()
{
var s=new Weather();
var o=new Board();
s.register(o);
s.setTemp({'value':99})
cd(o);
}
function Observer()
{
.....
this.dir={name:this.name,display:this.display}//you have to add all class's parms and fucntions pointer in the 'dir' arraylist,also do it in Subject class
}
//after this ,than you can add this class
function Combine()
{
var f1=new Subject();
var f2=new Observer();
var me={};
for (i in f1.dir)
{
me[i]=f1.dir[i];
}
for (i in f2.dir)
{
me[i]=f2.dir[i];
}
return me;
}
function Station()
{
var father =new Combine();
return father;
}
//then finally you get combine class
| Blog: |
| Wolke Codes |
Topics: |