草庐IT

function-prototypes

全部标签

Javascript "classes"原型(prototype) vs 内部函数声明 vs 等

我知道之前已经有人回答过这个问题,但我仍然感到困惑(这不完全是我的错,因为我注意到答案可能完全不同)。我有Java背景,所以如果你能将任何东西定义为静态、私有(private)、公共(public)等,那应该有助于我理解。基本上我想制作一个完全自定义的类,但不确定原型(prototype)/等。示例(使用一种函数类型):functionmyClass(){vara;varb;varhelper=function(){this.a+=this.b;}varhelper2=function(a,b){return(a+b);}vargetA=function(){return(this.a

通过 Object.create() 的 Javascript 原型(prototype)

varsomeObj=function(){}varp=newsomeObj();alert(someObj.prototype);//Thisworksalert(p.prototype);//UNDEFINED,butwhy?someObj.prototype.model="Nissan";alert(p.model);//Thisworks!Iunderstandthedynamicnatureofprototypes,butdoesn'tthatmeanthatp.prototype===someObj.prototype?为什么会这样?由于“p”是“someObj”的一个实例

javascript - 什么是 Array.map(Function.call,Number)

vararray1=[1,4,9,16];map1=array1.map(Function.call,Number);为什么map1的输出是[0,1,2,3],这个map函数是干什么的? 最佳答案 Array.prototype.map调用为数组的每个成员提供的函数,并返回一个由它们的返回值组成的新数组。在这种情况下,提供的函数是Function.call.Array.prototype.map的第二个参数指定所提供的函数应该运行的上下文。在这种情况下,上下文是Number.Array.prototype.map的简单实现可能类似于

javascript - Angular - TypeError : XX is not a function

也许我缺少某种属性,但我正在关注这个project我在我的Controller中收到此错误。TypeError:loginService.signinisnotafunction这是我的controller.jsangular.module('appcontrollers',[]).controller('LoginController',['$rootScope','$scope','$http','$location','$localStorage','loginService',function($rootScope,$scope,$http,loginService){$sco

javascript - React.js 和 ES6 : Any reason not to bind a function in the constructor

我正在将React组件更新为ES6,遇到了这个问题中描述的问题-UnabletoaccessReactinstance(this)insideeventhandler-即不绑定(bind)到组件实例。这是有道理的,当然也行得通,但我对答案的另一部分感到困惑:Beawarethatbindingafunctioncreatesanewfunction.Youcaneitherbinditdirectlyinrender,whichmeansanewfunctionwillbecreatedeverytimethecomponentrenders,orbinditinyourconstru

javascript - Javascript 中类属性和函数原型(prototype)的区别

我想了解Javascript中类属性和原型(prototype)之间的区别,我的意思在代码中显示:functionRectangle(x,y){this.width=x;this.height=y;}Rectangle.UNIT=newRectangle(1,1);Rectangle.prototype.UNIT=newRectangle(1,1);我知道原型(prototype)的工作方式类似于继承对象,这意味着UNIT将从现在开始显示所有实例,但Rectangle.UNIT=newRectangle(1,1);代码不会做同样的事情? 最佳答案

javascript - 参数类型 Number 不可分配给参数类型 String|Function

varstr=name.toUpperCase();varch=newArray();ch=str.split('');for(vari=0;i=97){varpos=i+1;result_code.replace(pos.toString()+pos.toString()+pos.toString()+pos.toString(),(temp-temp_integer)+40);}}}此代码在这一行result_code.replace(pos.toString()+pos.toString()+pos.toString()+pos.toString(),(temp-temp_int

javascript - 错误 : [ng:areq] Argument 'MyCtrl' is not a function, 未定义

我是Angularjs的新手,我正在学习教程,但我在标题中遇到了错误。HTML代码:IDNameSurnameHouseAddressLocalityContactContact2Contact3ReplyEdit{{person.ID}}{{person.Name}}{{person.Surname}}{{person.House}}{{person.Address}}//DefiningaAngularmodulevarmyApp=angular.module('myApp',[]);//DefiningaAngularControllermyApp.controller('MyC

Javascript静态与实例,原型(prototype)关键字

我想知道下面两段代码的区别我的理解是这是静态的,因为无需使用new关键字创建实例,就可以调用getCookie和setCookie函数。varCookieHandler=function(){};CookieHandler.getCookie=function(key){};CookieHandler.setCookie=function(key,value){};这是实例。在这种情况下,您需要创建一个实例来调用函数。varCookieHandler=function(){};CookieHandler.prototype.getCookie=function(key){};Cooki

javascript - _react2.default.PropTypes.function 未定义

所以我有一个按钮组件importReact,{Component}from'react';import{View,Text,TouchableNativeFeedback}from'react-native';classButtonextendsComponent{generateComponent(){const{buttonStyle,textStyle}=this.styles;const{text}=this.props;switch(this.props.platform){case'android':return({text});case'ios':return0;}}re