我现在学的都是prototype.js。有件事看起来很奇怪。例如,下面是我在firebug中运行的代码片段,url是,因为页面中有prototype.js。
var el2 = document.createElement('div');
var k=0;
for(var i in el2){ k++};
console.log(k);
结果是262,非常非常奇怪。因为如果在没有prototype.js的情况下在页面中运行相同的代码,结果是195。我的问题是prototype.js如何影响document.createElement方法。我在prototype.js中查询doc
我试图更好地掌握javascript类的内容和原因。具体来说,我试图理解将一个方法分配给一个原型和使用一个this.methodName =函数.构造函数中的语句。所以,我做了一个实验:
function CThis(){
this.method= function() {
console.log("method of ",this);
};
}
function CProto(){
}
CProto.prototype.method = function() {
console.log("method of ",this);
};
w
有人能说出js中的"this“关键字吗?我看了一些例子。有一点我不能理解。
A.B=function()
{
this.x(5); // this refers to prototype of A.B
}
A.B.prototype= {
x:function(p)
{ this.a(p); // this refers to prototype of A.B again
// but I expect that this refers to protoype of x ???
我在Angular.js模块中有一个对象声明:
$scope.test=function(){
};
$scope.test.prototype.push = function(data) {
return data;
};
我这样叫它:
var a = $scope.test.push(1);
console.error(a);
但我知道这个错误:
Error: undefined is not a function (evaluating '$scope.test.push(1)')
为什么我不能访问我通过Prototyp
我正在寻找以类似于Java类的方式编写面向对象的JavaScript (JS)代码的最佳方法。
工厂函数(FFs)看起来是在JS中提供类类功能的一种非常有希望的方法,到目前为止,我一直在这样构建它们:
function FF(constructorArg)
{
var _privateName = constructorArg;
var publicMessage = "Hello StackOverflow";
function publicMethodGetName() {
return _privateName;
}
ret
我正在学习一些JS,我希望有人能用简单的术语向我解释Object.getPrototypeOf()与.prototype之间的区别。
function ParentClass() {}
function ChildClass() {}
ChildClass.prototype = new ParentClass();
var mychild = new ChildClass();
var myparent = new ParentClass();
# .getPrototypeOf
Object.getPrototypeOf(ChildClass.prototype) // Pa
我使用的是jQuery、jQuery mobile、prototype和photoswipe的组合。我意识到由于$快捷方式的使用,jQuery和prototype之间存在冲突。所以我做了一个jQuery.noConflict()。现在,在我的Firebug控制台中,它不再报告任何错误。但是,当我转到Firebug DOM标记时,我看到:
当我检查4725行时,它是var $continue = new Error('"throw $continue" is deprecated, use "return" instead');。这就是我在使用j