// Base class
var Base = function() {
this._value = 'base';
};
Base.prototype = {
constructor: Base,
// By function
getValue: function() {
return this._value;
},
// By getter
get value() {
return this._value;
}
};
// Sub class extends Base
var Sub = function() {
this._value = 'sub';
};
Sub.prototype = {
constructor: Sub
};
// Pass over methods
Sub.prototype.getValue = Base.prototype.getValue;
Sub.prototype.value = Base.prototype.value;
// ---
var mySub = new Sub();
alert(mySub.getValue()); // Returns 'sub'
alert(mySub.value); // Returns …Run Code Online (Sandbox Code Playgroud) 我正在阅读JS Function的arguments变量的MDN页面:
https://developer.mozilla.org/en/JavaScript/Reference/Functions_and_function_scope/arguments
我知道参数不是数组,所以这不起作用:
var a = arguments.slice();
Run Code Online (Sandbox Code Playgroud)
MDN上的解决方案是这样做的:
var args = Array.prototype.slice.call(arguments);
Run Code Online (Sandbox Code Playgroud)
为什么使用Array.prototype而不仅仅是Array.slice.call(arguments)?在这里使用原型显着吗?
只是一个简单的问题,任何人都可以告诉我为什么这不起作用以及如何解决它?本质上,它采用HTML中的一组表行并动态地将点击事件附加到它们.
for (var a=index; a<rows.length; a++) {
tr = rows[a];
tr.onclick = function() { DropDownManager.onItemClick(tr, a); };
tr.observe("click", function() { DropDownManager.onItemClick(tr, a); });
}
Run Code Online (Sandbox Code Playgroud)
这段代码的问题是传递给DropDownManager.onItemClick的值总是循环中的最后一项,这不是我想要的那样,因为我希望它们是循环那个阶段的当前值.我意识到我错过了一些非常简单但却无法解决我生活的问题!
我制作了一个模式来使用他们的原型创建和扩展html元素.这就像非浏览器中的魅力一样.示例代码可以在@jsbin找到(参见页面源代码)
这种模式的优点应该是速度(方法在元素原型链中,因此它们被引用一次).你猜对了:IE没有去.在IE <8中,html元素的原型是隐藏/不可访问的,因此对于您创建的每个元素,您必须再次引用非标准方法(如果您密集使用该模式,请留下很多指针).我在网上搜索了解决方案,但只找到了复杂的解决方法.有没有真的没有办法在IE浏览器访问HTML元素的原型?
比方说son,我有一些对象,我想从另一个对象继承father.
当然我可以为父亲创建一个构造函数
Father = function() {
this.firstProperty = someValue;
this.secondProperty = someOtherValue;
}
Run Code Online (Sandbox Code Playgroud)
然后使用
var son = new Father();
son.thirdProperty = yetAnotherValue;
Run Code Online (Sandbox Code Playgroud)
但这不是我想要的.由于son将具有许多属性,因此将子声明为对象文字将更具可读性.但后来我不知道如何设置它的原型.
做点什么
var father = {
firstProperty: someValue;
secondProperty: someOtherValue;
};
var son = {
thirdProperty: yetAnotherValue
};
son.constructor.prototype = father;
Run Code Online (Sandbox Code Playgroud)
不会起作用,因为原型链似乎是隐藏的而不关心构造函数.prototype的变化.
我想我可以__proto__在Firefox中使用该属性,比如
var father = {
firstProperty: someValue;
secondProperty: someOtherValue;
};
var son = {
thirdProperty: yetAnotherValue
__proto__: father
};
son.constructor.prototype = father;
Run Code Online (Sandbox Code Playgroud)
但是,据我所知,这不是该语言的标准功能,最好不要直接使用它.
有没有办法为对象文字指定原型?
Family = function(name) {
this._Name = name;
}
Family.prototype = {
getName: function() {
return this._Name;
},
People: function(num) {
this._Number = num;
}
}
Family.People.prototype = {
clearNumber: function() {
this._Number = 0;
}
}
Run Code Online (Sandbox Code Playgroud)
人是一个嵌套的类.它的父类是Family.
我得到了Family.People未定义的错误.有人可以纠正上面的代码吗?
D3.js是否能够支持醉酒的工具提示?如果可能,有人可以给我看一个例子.谢谢.
我很难尝试使用webclient对accounts.google.com进行身份验证
我正在使用C#WebClient对象来实现以下功能.
我将表单字段提交到https://accounts.google.com/ServiceLoginAuth?service=oz
这是POST字段:
service=oz
dsh=-8355435623354577691
GALX=33xq1Ma_CKI
timeStmp=
secTok=
Email=test@test.xom
Passwd=password
signIn=Sign in
PersistentCookie=yes
rmShown=1
Run Code Online (Sandbox Code Playgroud)
现在,在我提交数据之前加载登录页面时,它有以下标题:
Content-Type text/html; charset=UTF-8
Strict-Transport-Security max-age=2592000; includeSubDomains
Set-Cookie GAPS=1:QClFh_dKle5DhcdGwmU3m6FiPqPoqw:SqdLB2u4P2oGjt_x;Path=/;Expires=Sat, 21-Dec-2013 07:31:40 GMT;Secure;HttpOnly
Cache-Control no-cache, no-store
Pragma no-cache
Expires Mon, 01-Jan-1990 00:00:00 GMT
X-Frame-Options Deny
X-Auto-Login realm=com.google&args=service%3Doz%26continue%3Dhttps%253A%252F%252Faccounts.google.com%252FManageAccount
Content-Encoding gzip
Transfer-Encoding chunked
Date Thu, 22 Dec 2011 07:31:40 GMT
X-Content-Type-Options nosniff
X-XSS-Protection 1; mode=block
Server GSE
Run Code Online (Sandbox Code Playgroud)
好了,现在我如何使用WebClient Class来包含这些标题?
我尝试过,webClient_.Headers.Add();但效果有限,总是返回登录页面.
以下是我使用的课程.非常感谢任何帮助.
获取登录页面
public void LoginPageRequest(Account acc)
{
var rparams = new RequestParams();
rparams.URL = @"https://accounts.google.com/ServiceLoginAuth?service=oz"; …Run Code Online (Sandbox Code Playgroud) 假使,假设
n = u"Tübingen"
repr(n) # `T\xfcbingen` # Unicode
i = 1 # integer
Run Code Online (Sandbox Code Playgroud)
抛出以下第一个文件
UnicodeEncodeError: 'ascii' codec can't encode character u'\xfc' in position 82: ordinal not in range(128)
Run Code Online (Sandbox Code Playgroud)
当我这样做的n.encode('utf8')时候.
第二种方法在两种情况下都完美无瑕.
# Python File 1
#
#!/usr/bin/env python -B
# encoding: utf-8
print '{id}, {name}'.format(id=i, name=n)
Run Code Online (Sandbox Code Playgroud)
# Python File 2
#
#!/usr/bin/env python -B
# encoding: utf-8
print '%i, %s'% (i, n)
Run Code Online (Sandbox Code Playgroud)
由于在文档中鼓励使用format()而不是%格式运算符,我不明白为什么format()看起来更"残缺".难道format()只能用工作utf8-strings?
我有这样的错误
Undefined symbols for architecture i386:
"_OBJC_CLASS_$_ViewController", referenced from:
objc-class-ref in AppDelegate.o
ld: symbol(s) not found for architecture i386
clang: error: linker command failed with exit code 1 (use -v to see invocation)
Run Code Online (Sandbox Code Playgroud)
你怎么解决这个问题?请帮我.