谁能告诉我你用于分析的工具,比如kcachegrind wingrind valgrind for mac platform.
我不认为这些工作在Mac上,我也快速检查.
window.onload = function(){
var obj = '{
"name" : "Raj",
"age" : 32,
"married" : false
}';
var val = eval('(' + obj + ')');
alert( "name : " + val.name + "\n" +
"age : " + val.age + "\n" +
"married : " + val.married );
}
Run Code Online (Sandbox Code Playgroud)
在像这样的代码中,我试图创建JSON字符串只是为了玩.这是错误,但如果我把所有的名字,年龄,结婚在一行(第2行),它不会.有什么问题?
var Ob = function(){
}
Ob.prototype.add = function(){
inc()
}
Ob.prototype.inc = function(){
alert(' Inc called ');
}
window.onload = function(){
var o = new Ob();
o.add();
}
Run Code Online (Sandbox Code Playgroud)
我想打电话给这样的话,我怎么称呼,当然我把inc作为内部函数来添加我可以做到但是没有内部函数.我怎么做 ?
在下面的代码中,我想有一个计数器来跟踪创建的Person对象的数量.这段代码没有这样做,我怎么做到这一点?
function Person(){
this.name = "Peter";
this.counter = this.counter + 1;
alert(this.counter);
}
Person.prototype.counter = 0;
var p1 = new Person;
var p2 = new Person;
Run Code Online (Sandbox Code Playgroud) 你能告诉我这种特定语法结构的原因吗?
eval('(' + jsonString+ ')')
Run Code Online (Sandbox Code Playgroud)
解析json文本时.克罗克福德说:" 文本必须用parens包装,以避免绊倒JavaScript语法中的歧义." 在这里.那是什么意思?
我们能避免吗?
我有一排相同尺寸的照片显示,当你连续没有足够数量的照片时,照片应该在宽度上扩大以占据整个空间.可以有3个内部div或4个内部div.
// CSS Section
.cont {
position : absolute;
background : #E4EDF7;
border : 1px solid grey;
height: 200px;
width:400px;
}
.ibox {
float: left;
background : green;
margin: 5px;
border: 1px solid grey;
height: 50px;
width: 100px;
}
// HTML Markup
<div class="cont">
<div class="ibox"></div>
<div class="ibox"></div>
<div class="ibox"></div>
<div class="ibox"></div>
<div class="ibox"></div>
</div>
Run Code Online (Sandbox Code Playgroud) 有人可以发现这段代码出了什么问题,我的firebug控制台上出现了无效的标签错误.
<script type="text/javascript">
var a = function(){
this.prop1:"value1", //Error here
this.prop2:"value2"
}
var b = new a();
</script>
Run Code Online (Sandbox Code Playgroud) 让我们说我们有窗口对象的警报方法.我想用漂亮的警报器来增强它.
此外,我想保存现有的警报方法,以便我们可以在应用程序结束后切换回来.
像这样的东西,但它在firefox控制台中抛出错误.
window.prototype.alert = function(){
}
Run Code Online (Sandbox Code Playgroud) 我如何声明受保护的变量.我在这里举个例子
// Constructor
function Car(){
// Private Variable
var model;
}
// Public variable
Car.prototype.price = "5 Lakhs";
// Subtype
function Indiancar(){
}
// Prototype chaining
Indiancar.prototype = new Car();
// Instantiating Superclass object
var c = new Car();
// Instantiating subclass object
var ic = new Indiancar();
Run Code Online (Sandbox Code Playgroud)
在这里我想有一个可以作为ic.variabl访问的变量,它也存在于汽车类中.