Modernizrのソースコードにこの抜粋があります。javascriptでcall.callが達成すること
var documentCreateElement = scopeDocument.createElement, documentCreateDocumentFragment = scopeDocument.createDocumentFragment;
// shiv the document
for (var i = 0, elements = html5.elements, l = elements.length; i < l; ++i) {
call.call(documentCreateElement, scopeDocument, elements[i]);
}
// shiv the document create element method
scopeDocument.createElement = function (nodeName) {
var element = call.call(documentCreateElement, scopeDocument, nodeName);
対立するものとしてdocumentCreateElement.call(scopeDocument,nodeName)
ないことだけcall
何を達成されたために、call.call
を使用する必要があった理由を私は不思議でしたか?事前
確かにこれは 'call'が何であるかにかかっていますか? 'documentCreateElement.call(...)'は 'documentCreateElement'を呼び出します。 'call.call'は' call'を呼び出します。したがって、 'call.call(documentCreateElement、...) '' call'が 'Function.prototype.call'の場合にのみ' documentCreateElement'を呼び出します - 名前にもかかわらず、そうではないかもしれません。 – ruakh
(これを少し不透明にするには、コードが 'CALL.call(documentCreateElement、...)'であったとします。 'documentCreateElement.call(...)'と同じであると仮定しますか?変数 'CALL'の名前が' call'に変更されているので、関数オブジェクトの 'call'メソッドのコピーであるとは限りません)。 – ruakh
@ruakh [source code]( http://www.modernizr.com/downloads/modernizr-2.5.2.js)。 'call' - >' Date.call' - > 'Function.prototype.call'です。 –