$('#showPdf').click(function() {
var pdf = new jsPDF();
pdf.addHTML($("#divContent"), function() {
var blob = pdf.output("blob");
window.open(URL.createObjectURL(blob));
});
});
$('#downloadPdf').click(function() {
var pdf = new jsPDF();
pdf.addHTML($("#divContent"), function() {
pdf.save('pageContent.pdf');
});
});
我现在想要重新定义方法 <script src="https://cdnjs.cloudflare.com/ajax/libs/jspdf/1.3.2/jspdf.debug.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<div id="divContent" style="background-color: white; padding:20px 25px">
<h3>SEA MINK</h3>
<p>The sea mink (Neovison macrodon) was a mammal from the eastern coast
of North America, in the family of weasels and otters in the order Carnivora.
The largest of the minks, it was hunted to extinction by fur traders before 1903,
when it was first given a species description. Some biologists classify it as a subspecies of the
American mink. Estimates of its size are speculative, based largely on skull fragments recovered
from Native American shell middens, and on tooth remains. Some information on its appearance and
habits was provided by fur traders and Native Americans. It may have been similar in behavior to
the American mink: it probably maintained home ranges, was polygynandrous, and had a similar diet,
supplemented by saltwater prey. Sea minks were commonly trapped along the coast of the Bay of
Fundy in the Gulf of Maine. Remains have been found along the New England coast, and there were r
egular reports of unusually large mink furs, probably sea mink, being collected from Nova Scotia</p>
<img src="data:image/jpeg;base64,/9j/4AAQSkZJRgABAQAAAQABAAD/2wCEAAkGBwgHBgkIBwgKCgkLDRYPDQwMDRsUFRAWIB0iIiAdHx8kKDQsJCYxJx8fLT0tMTU3Ojo6Iys/RD84QzQ5OjcBCgoKDQwNGg8PGjclHyU3Nzc3Nzc3Nzc3Nzc3Nzc3Nzc3Nzc3Nzc3Nzc3Nzc3Nzc3Nzc3Nzc3Nzc3Nzc3Nzc3N//AABEIAGMAYwMBEQACEQEDEQH/xAAbAAEAAgMBAQAAAAAAAAAAAAAABAYBAwUCB//EADgQAAEDAwEGAgYKAgMAAAAAAAEAAgMEBREGEiExQVFhE3EUMmKBkbEHFSIjQlJygqHBkvAzssL/xAAbAQEAAQUBAAAAAAAAAA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aYM1aR93Zrg89MRt/7PCshu1fSeuF6+2R0iBg2/UNYdlnodsi3fePJqJSOY2RhrT3y7yW1td16cdbiefBafX/ABEcrh/xJ9m0rbrXUOrCJKu4PbsyVtU7blcOgPBrfZaAOy6ehQp0IfDpRwjHbbeWd0DHBSlAgCAIAgCAIAgCAIAgCAIAgCAIAgCAIAgCAIAgCAIAgCAIAgCA/9k="/>
</div>
<button id="showPdf">Generate PDF</button>
<button id="downloadPdf">Download PDF</button>
并在运行时添加一个案例:
class Foo{
private final Object obj0;
private final Object obj1;
private final Object def;
Public Foo(obj0,obj1,def){
this.obj0 = obj0;
this.obj1 = obj1;
this.def = def;
}
public int foo(long v){
if (v==0) return obj0;
else if (v==1) return obj1;
else return def;
}
}
现在从概念上讲这听起来很简单。在伪代码中:
Foo.foo
问题是我们正在使用字节码而AST并不真正处理语句,更不用说IF抽象了。
所以我在这个案例中可以做的就是使用这样一个事实,即所有守卫都是互斥的,每个案例都会自行返回,只需重新定义方法,如
class Foo{
private final Object obj0;
private final Object obj1;
private final Object def;
Public Foo(obj0,obj1,def){
this.obj0 = obj0;
this.obj1 = obj1;
this.def = def;
}
public int foo(long v){
if (v==0) return obj0;
else if (v==1) return obj1;
else if (v==2) return obj2_fixed_when_added;
else return def;
}
}
基本上是
visit method Foo.foo{
boolean transformed = false;
for(stmt : Foo.foo.body){
if (transformed || stmt is not if){
emit unchanged
}else if (stmt is IF){
visit if-clause
visit else-clause
emit IF
}else{
emit new ELSIF for case v==2
emit stmt unchanged
transformed = true;
}
}
}
原油,但我的工作就完成了,我们现在可以重新加载课程以进行更改。
问题就变成了
public int foo(long v){
if (v==2) return obj2_fixed_when_added;
if (v==0) return obj0;
else if (v==1) return obj1;
else return def;
}
如果我可以创建任何visit method Foo.foo{
emit new IF for v==2
emit rest of method body unchanged
}
的新实例,我就会这样做。
但是,如果我不能并且想要将其设置为变换器在插入新IF时生成的特定对象,该怎么办?