javascript中部分不能使用call apply调用来重写的构造函数

  This tests if TypeError is thrown or not when we call a constructor as a normal function.
   
  On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
   
   
  PASS ArrayBuffer() threw exception TypeError: Constructor ArrayBuffer requires ‘new‘.
  SKIP AudioContext is not implemented.
  PASS FormData() threw exception TypeError: Failed to construct ‘DOMFormData‘: Please use the ‘new‘ operator, this DOM object constructor cannot be called as a function..
  PASS DataView() threw exception TypeError: Constructor DataView requires ‘new‘.
  PASS EventSource() threw exception TypeError: Failed to construct ‘EventSource‘: Please use the ‘new‘ operator, this DOM object constructor cannot be called as a function..
  PASS FileReader() threw exception TypeError: Failed to construct ‘FileReader‘: Please use the ‘new‘ operator, this DOM object constructor cannot be called as a function..
  PASS Float32Array() threw exception TypeError: Constructor Float32Array requires ‘new‘.
  PASS Float64Array() threw exception TypeError: Constructor Float64Array requires ‘new‘.
  PASS Audio() threw exception TypeError: Failed to construct ‘HTMLAudioElement‘: Please use the ‘new‘ operator, this DOM object constructor cannot be called as a function..
  PASS Image() threw exception TypeError: DOM object constructor cannot be called as a function..
  PASS Option() threw exception TypeError: Failed to construct ‘HTMLOptionElement‘: Please use the ‘new‘ operator, this DOM object constructor cannot be called as a function..
  PASS Int16Array() threw exception TypeError: Constructor Int16Array requires ‘new‘.
  PASS Int32Array() threw exception TypeError: Constructor Int32Array requires ‘new‘.
  PASS Int8Array() threw exception TypeError: Constructor Int8Array requires ‘new‘.
  PASS MessageChannel() threw exception TypeError: Failed to construct ‘MessageChannel‘: Please use the ‘new‘ operator, this DOM object constructor cannot be called as a function..
  PASS SharedWorker() threw exception TypeError: Failed to construct ‘SharedWorker‘: Please use the ‘new‘ operator, this DOM object constructor cannot be called as a function..
  PASS Uint16Array() threw exception TypeError: Constructor Uint16Array requires ‘new‘.
  PASS Uint32Array() threw exception TypeError: Constructor Uint32Array requires ‘new‘.
  PASS Uint8Array() threw exception TypeError: Constructor Uint8Array requires ‘new‘.
  PASS WebKitCSSMatrix() threw exception TypeError: Failed to construct ‘CSSMatrix‘: Please use the ‘new‘ operator, this DOM object constructor cannot be called as a function..
  PASS WebKitPoint() threw exception TypeError: Failed to construct ‘DOMPoint‘: Please use the ‘new‘ operator, this DOM object constructor cannot be called as a function..
  PASS WebSocket() threw exception TypeError: Failed to construct ‘WebSocket‘: Please use the ‘new‘ operator, this DOM object constructor cannot be called as a function..
  PASS Worker() threw exception TypeError: Failed to construct ‘Worker‘: Please use the ‘new‘ operator, this DOM object constructor cannot be called as a function..
  PASS XMLHttpRequest() threw exception TypeError: Failed to construct ‘XMLHttpRequest‘: Please use the ‘new‘ operator, this DOM object constructor cannot be called as a function..
  PASS XSLTProcessor() threw exception TypeError: Failed to construct ‘XSLTProcessor‘: Please use the ‘new‘ operator, this DOM object constructor cannot be called as a function..
  PASS successfullyParsed is true
   
  TEST COMPLETE

https://chromium.googlesource.com/chromium/blink/+/8fefa5dc50de232902601612bf6429f08779abc9/LayoutTests/fast/dom/call-a-constructor-as-a-function-expected.txt

时间: 2024-11-19 04:10:09

javascript中部分不能使用call apply调用来重写的构造函数的相关文章

移花接木—— 再谈javascript中的 call 与 apply

在JavaScript中,call 和 apply 是Function对象自带的两个方法,这两个方法的主要作用是改变函数中的this指向,从而可以达到`接花移木`的效果.本文将对这两个方法进行详细的讲解,并列出几个关于call和apply的经典应用场景. call(thisArgs [,args...]) 该方法可以传递一个thisArgs参数和一个参数列表,thisArgs指定了函数在运行期的调用者,也就是函数中的this对象,而参数列表会被传入调用函数中.thisArgs的取值有以下4种情况

浅谈javascript中的call、apply、bind

apply.call 在 javascript 中,call 和 apply 都是为了改变某个函数运行时的上下文(context)而存在的,换句话说,就是为了改变函数体内部 this 的指向. JavaScript 的一大特点是,函数存在「定义时上下文」和「运行时上下文」以及「上下文是可以改变的」这样的概念. 先来一个栗子: function fruits() {} fruits.prototype = { color: "red", say: function() { console

Javascript中call方法和apply方法用法和区别

第一次在博客园上面写博客,知识因为看书的时候发现了一些有意思的知识,顺便查了一下资料,就发到博客上来了,希望对大家有点帮助. 连续几天阅读<javascript高级程序设计>这本书了,逐渐发现了以前很多自己完全没有用过甚至见过的神奇知识点.今天在阅读到有关函数的属性和方法的时候,略感高级,于是乎,查阅了不少他人的博客,在此总结一下这两个方法的以下几个方面: 1.call()和apply()的作用和用法 2.什么时候用apply(),什么时候用call() 书上提到,每个函数都包含两个非继承而来

Javascript中call函数和apply函数的使用

Javascript 中call函数和apply的使用: Javascript中的call函数和apply函数是对执行上下文进行切换,是将一个函数从当前执行的上下文切换到另一个对象中执行,例如: sourceObj.method.call(destObj,params1,params2) 是将sourceObj中的method函数放在destObj中执行 call函数还有另外一种重要的作用,在Javascript面向对象编程中实现多继承的作用,例如: function parentClass()

JavaScript中的call、apply

JavaScript中的call.apply call JavaScript中的call是调用一个函数,在调用函数时,将this的值绑定为call参数中的第一个参数. var bye = function(param, param2){ console.log(this); console.log(param); console.log(param2); console.log("bye"); console.log(this.x) } t = {'x': 1}; bye.call(t

javascript中的call()和apply()方法的使用

1.方法定义 call方法: 语法:call([thisObj[,arg1[, arg2[,   [,.argN]]]]]) 定义:调用一个对象的一个方法,以另一个对象替换当前对象. 说明: call 方法可以用来代替另一个对象调用一个方法.call 方法可将一个函数的对象上下文从初始的上下文改变为由 thisObj 指定的新对象. 如果没有提供 thisObj 参数,那么 Global 对象被用作 thisObj. apply方法: 语法:apply([thisObj[,argArray]])

理解和运用javascript中的call及apply

call是为了改变函数上下文context而存在的,换言之,就是改变函数内部this的指向.因为javascript存在[定义时上下文],[运行时上下文]及[上下文]是可以改变的.例如:var func1 = function(arg1, arg2) {}; 就可以通过 func1.call(this, arg1, arg2); 或者 func1.apply(this, [arg1, arg2]); 来调用.其中 this 是你想指定的上下文,他可以任何一个 JavaScript 对象(Java

JavaScript中的call()、apply()与bind():

关于call()与apply(): 在JavaScript中,每个函数都有call与apply(),这两个函数都是用来改变函数体内this的指向,并调用相关的参数. 看一个例子: 定义一个animal对象,该对象有一个jump()方法: var animal = { type:'animal', jump:function(name){ return this.type + ' is ' + name; } } some_animal.jump('dog'); **"animal is dog&

Javascript中函数的四种调用方式

一.Javascript中函数的几个基本知识点: 1.函数的名字只是一个指向函数的指针,所以即使在不同的执行环境,即不同对象调用这个函数,这个函数指向的仍然是同一个函数. 2.函数中有两个特殊的内部属性:arguments和this. arguments主要是用来保存函数参数,arguments中的callee属性主要是用来指向拥有当前arguments的函数(理解Javascript参数中的arguments对象). 3.在ECMAScript5中规范了另一个函数属性:caller(Opera