草庐IT

Prototype

全部标签

javascript - JavaScript 中 [[prototype]] 属性的双括号有何意义?

我知道每个JavaScript对象都有一个名为[[Prototype]]的内部属性。一些实现允许通过名为__proto__的属性访问它,而其他实现则不允许。这个属性周围的括号有什么特殊意义吗? 最佳答案 它是对象的“内部属性”。来自ECMAScript8.6.2:Thisspecificationusesvariousinternalpropertiestodefinethesemanticsofobjectvalues.TheseinternalpropertiesarenotpartoftheECMAScriptlanguage

javascript - 扩展 Object.prototype JavaScript

我不是在问这是否可以:Object.prototype.method=function(){};几乎每个人都认为这是邪恶的,因为它搞砸了for(variinobj)。真正的问题忽略不称职的浏览器(不支持Object.defineProperty的浏览器)属性冲突或覆盖的可能性假设您有一些难以置信有用的方法,这是否被认为是错误的/不道德的?Object.defineProperty(Object.prototype,'methodOnSteriods',{value:function(){/*Makesbreakfast,solvesworldpeace,takesouttrash*/}

javascript - 扩展 Object.prototype JavaScript

我不是在问这是否可以:Object.prototype.method=function(){};几乎每个人都认为这是邪恶的,因为它搞砸了for(variinobj)。真正的问题忽略不称职的浏览器(不支持Object.defineProperty的浏览器)属性冲突或覆盖的可能性假设您有一些难以置信有用的方法,这是否被认为是错误的/不道德的?Object.defineProperty(Object.prototype,'methodOnSteriods',{value:function(){/*Makesbreakfast,solvesworldpeace,takesouttrash*/}

javascript - typescript 错误运行时错误: Cannot read property 'prototype' of undefined when extending

所以我在控制台中收到上述错误。这是由于_super在传递给__extends(在生成的.js中)时未定义。下面是一些可用于重现错误的测试代码://ThisistheentiretyofthefileTest.tsmoduleTest{exportclassTest1{publicName:string;publicNumber:number;constructor(){}}}然后在一个单独的文件中,我有一个继承自该文件的类:///moduleTest{exportclassTest2extendsTest1{constructor(){super();}}}不应该需要(实际上也不需要)

javascript - typescript 错误运行时错误: Cannot read property 'prototype' of undefined when extending

所以我在控制台中收到上述错误。这是由于_super在传递给__extends(在生成的.js中)时未定义。下面是一些可用于重现错误的测试代码://ThisistheentiretyofthefileTest.tsmoduleTest{exportclassTest1{publicName:string;publicNumber:number;constructor(){}}}然后在一个单独的文件中,我有一个继承自该文件的类:///moduleTest{exportclassTest2extendsTest1{constructor(){super();}}}不应该需要(实际上也不需要)

javascript - 子类化 Javascript 数组。 TypeError : Array. prototype.toString 不是通用的

是否可以子类化并继承自javascript数组?我想要拥有自己的自定义Array对象,它具有Array的所有功能,但包含其他属性。如果实例是我的CustomArray,我将使用myobjinstanceofCustomArray执行特定操作。在尝试子类化并遇到一些问题后,我发现了这个DeanEdwards指示使用数组对象执行此操作不正确的文章。事实证明InternetExplorer无法正确处理它。但我也发现了其他问题(目前仅在Chrome中测试过)。下面是一些示例代码:/***Inherittheprototypemethodsfromoneconstructorintoanothe

javascript - 子类化 Javascript 数组。 TypeError : Array. prototype.toString 不是通用的

是否可以子类化并继承自javascript数组?我想要拥有自己的自定义Array对象,它具有Array的所有功能,但包含其他属性。如果实例是我的CustomArray,我将使用myobjinstanceofCustomArray执行特定操作。在尝试子类化并遇到一些问题后,我发现了这个DeanEdwards指示使用数组对象执行此操作不正确的文章。事实证明InternetExplorer无法正确处理它。但我也发现了其他问题(目前仅在Chrome中测试过)。下面是一些示例代码:/***Inherittheprototypemethodsfromoneconstructorintoanothe

javascript - 为什么在 JavaScript 中 "Object instanceof Function"和 "Function instanceof Object"都返回 true?

为什么在JavaScript中ObjectinstanceofFunction和FunctioninstanceofObject都返回true?我在SafariWebInspector中试过了。 最佳答案 我花了一段时间才弄明白,但这真的值得花时间。首先,让我们看看instanceof是如何工作的。引自MDN,Theinstanceofoperatortestswhetheranobjecthasinitsprototypechaintheprototypepropertyofaconstructor.[instanceof]现在,

javascript - 为什么在 JavaScript 中 "Object instanceof Function"和 "Function instanceof Object"都返回 true?

为什么在JavaScript中ObjectinstanceofFunction和FunctioninstanceofObject都返回true?我在SafariWebInspector中试过了。 最佳答案 我花了一段时间才弄明白,但这真的值得花时间。首先,让我们看看instanceof是如何工作的。引自MDN,Theinstanceofoperatortestswhetheranobjecthasinitsprototypechaintheprototypepropertyofaconstructor.[instanceof]现在,

JavaScript 继承和构造函数属性

考虑以下代码。functiona(){}functionb(){}functionc(){}b.prototype=newa();c.prototype=newb();console.log((newa()).constructor);//a()console.log((newb()).constructor);//a()console.log((newc()).constructor);//a()为什么不为b和c更新构造函数?我做错了继承吗?更新构造函数的最佳方法是什么?此外,请考虑以下事项。console.log(newa()instanceofa);//trueconsole.l