我没有找到如何在史前javascript(可能是1.2)中创建对象的方法:
现在我想做点什么:
var constructor = ...;
return constructor.apply(.?., parameterList);
或
var constructor = ...;
return new constructor(...parameterList);
可以在javascript中进行吗?我找到了一个正在创建重复对象的黑客。
var constructor = ...;
var instance = new constructor;
parameterList.length > 0 ? constructor.apply(instance, parameterList) : null;
return instance;
答案 0 :(得分:0)
将解决方案从问题转移到答案:
修改1.0
所以我找到了非常有趣的解决方案:
private List<WebElement> table = driver.findElements(By.xpath("//div[contains(@class,'hdrInv')]")); System.out.print("No of Tables: "+table.size()); for(int tabind=0; tabind<table.size(); tabind++){ System.out.println("ROWText: "+table.get(tabind).findElement(By.xpath(".//div[@class='col']/b")).getText()); }
一些缺点可能是一直显示
var instance = (function (constructor, parameterList) { var creator = constructor; function Constructor() { creator.apply(this, parameterList); } Constructor.prototype = creator.prototype; return new Constructor; }(...constructor function comes here..., parameterList));
(即使可能创建了真正的类型)。修改1.0.1
积分在这里:http://tobyho.com/2010/11/22/javascript-constructors-and/