CF 11+ Member Functions allow variables of certain CFML data types to be treated as objects with functions. Invoking a member function on the object (the variable) allows you to skip passing the variable into the function because it already has a reference to the value. The use of member functions often lead to more concise and readable code.
For instance, consider the following headless function:
arrayAppend(empArr, emp)
Using a member function it can be written as:
empArr.append(emp)
Where empArr
is a reference to an instance of a CFArray class (possibly a variable created with arrayNew).
The following example depicts the new usage of member functions:
// The standard way
var myArray = arrayNew(1);
arrayAppend(myArray, "objec_new");
arraySort(myArray, "ASC");
// The member way
myArray.append("objec_new");
myArray.sort("ASC");
// The member way
var myProductObject = createObject("java", "myJavaClass");
myJavaList = myProductObject.getProductList();
myJavaList.add("newProduct"); // Java API
myJavaList.append("newProduct"); // CF API
myJavaList.sort("ASC");
Member Functions can also be chained (on Lucee or CF 2018+), for example:
s = "the";
s = s.listAppend("quick brown fox", " ")
.listAppend("jumps over the lazy dog", " ")
.uCase()
.reverse();
result: GOD YZAL EHT REVO SPMUJ XOF NWORB KCIUQ EHT
Member functions for the following data types are supported:
CF 2016 changed the return type for append member functions:
someArray.append()
now returns the appended arraysomeStruct.append()
now returns the appended structuresomeVar.append()
someVar.avg()
someVar.clear()
someVar.contains()
someVar.containsNoCase()
someVar.delete()
someVar.deleteAt()
someVar.deleteNoCase()
someVar.each()
someVar.every()
someVar.filter()
someVar.find()
someVar.findAll()
someVar.findAllNoCase()
someVar.findNoCase()
someVar.first()
someVar.getMetaData()
someVar.insertAt()
someVar.isDefined()
someVar.isEmpty()
someVar.last()
someVar.len()
someVar.map()
someVar.max()
someVar.min()
someVar.prepend()
someVar.reduce()
someVar.reduceRight()
someVar.resize()
someVar.set()
someVar.slice()
someVar.some()
someVar.sort()
someVar.splice()
someVar.sum()
someVar.swap()
someVar.toList()
someVar.toJSON()
someVar.binaryDecode()
someVar.binaryEncode()
someVar.canonicalize()
someVar.charsetDecode()
someVar.charsetEncode()
someVar.cJustify()
someVar.compare()
someVar.compareNoCase()
someVar.decodeForHTML()
someVar.decodeFromURL()
someVar.decrypt()
someVar.encodeForCSS()
someVar.encodeForHTML()
someVar.encodeForHTMLAttribute()
someVar.encodeForJavaScript()
someVar.encodeForURL()
someVar.encodeForXML()
someVar.encodeForXMLAttribute()
someVar.encodeForXPath()
someVar.encrypt()
someVar.find()
someVar.findNoCase()
someVar.findOneOf()
someVar.formatBaseN()
someVar.generateSecretKey()
someVar.getSafeHTML()
someVar.getToken()
someVar.hash()
someVar.htmlCodeFormat()
someVar.htmlEditFormat()
someVar.insert()
someVar.isSafeHTML()
someVar.jsStringFormat()
someVar.lCase()
someVar.left()
someVar.len()
someVar.lJustify()
someVar.lsIsCurrency()
someVar.lsIsDate()
someVar.lsIsNumeric()
someVar.lsParseCurrency()
someVar.lsParseDateTime()
someVar.lsParseEuroCurrency()
someVar.lsParseNumber()
someVar.mid()
someVar.paragraphFormat()
someVar.parseDateTime()
someVar.reFind()
someVar.reFindNoCase()
someVar.reMatch()
someVar.reMatchNoCase()
someVar.removeChars()
someVar.repeatString()
someVar.replace()
someVar.replaceList()
someVar.replaceListNoCase()
someVar.replaceNoCase()
someVar.reReplace()
someVar.reReplaceNoCase()
someVar.reverse()
someVar.right()
someVar.rJustify()
someVar.trim()
someVar.toJSON()
someVar.spanExcluding()
someVar.spanIncluding()
someVar.each()
someVar.every()
someVar.filter()
someVar.map()
someVar.reduce()
someVar.reduceRight()
someVar.some()
someVar.sort()
someVar.stripCR()
someVar.toBase64()
someVar.toBinary()
someVar.toString()
someVar.trim()
someVar.uCase()
someVar.urlDecode()
someVar.urlEncodedFormat()
someVar.val()
someVar.wrap()
someVar.xmlFormat()
someVar.listAppend()
someVar.listChangeDelims()
someVar.listContains()
someVar.listContainsNoCase()
someVar.listDeleteAt()
someVar.listEach()
someVar.listFind()
someVar.listFindNoCase()
someVar.listFirst()
someVar.listGetAt()
someVar.listInsertAt()
someVar.listLast()
someVar.listLen()
someVar.listMap()
someVar.listPrepend()
someVar.listQualify()
someVar.listReduce()
someVar.listReduceRight()
someVar.listRemoveDuplicates()
someVar.listRest()
someVar.listSetAt()
someVar.listSort()
someVar.listToArray()
someVar.listValueCount()
someVar.listValueCountNoCase()
someVar.toJSON()
someVar.toJSON()
someVar.append()
someVar.clear()
someVar.copy()
someVar.count()
someVar.delete()
someVar.each()
someVar.every()
someVar.filter()
someVar.find()
someVar.findKey()
someVar.findValue()
someVar.get()
someVar.getMetadata()
someVar.insert()
someVar.isCaseSensitive()
someVar.isEmpty()
someVar.isOrdered()
someVar.keyArray()
someVar.keyExists()
someVar.keyList()
someVar.map()
someVar.reduce()
someVar.setMetadata()
someVar.some()
someVar.sort()
someVar.toSorted()
someVar.update()
someVar.createODBCDate()
someVar.createODBCDateTime()
someVar.createODBCTime()
someVar.add()
someVar.convert()
someVar.diff()
someVar.dateFormat()
someVar.datePart()
someVar.dateTimeFormat()
someVar.day()
someVar.dayOfWeek()
someVar.dayOfYear()
someVar.daysInMonth()
someVar.daysIn
someVar.firstDayOfMonth()
someVar.format()
someVar.hour()
someVar.lsDateFormat()
someVar.lsTimeFormat()
someVar.millisecond()
someVar.minute()
someVar.month()
someVar.quarter()
someVar.second()
<DateObject>.setDay(day)
<DateObject>.setHour(hour)
<DateObject>.setMinute(minute)
<DateObject>.setMonth(month)
<DateObject>.setSecond(second)
<DateObject>.setYear(year)
someVar.timeFormat()
someVar.week()
someVar.year()
someVar.addBorder()
someVar.blur()
someVar.clearRect()
someVar.copy()
someVar.crop()
someVar.drawArc()
someVar.drawBeveledRect()
someVar.drawCubicCurve()
someVar.drawLine()
someVar.drawLines()
someVar.drawOval()
someVar.drawPoint()
someVar.drawQuadraticCurve()
someVar.drawRect()
someVar.drawRoundRect()
someVar.drawText()
someVar.flip()
someVar.getBlob()
someVar.getBufferedImage()
someVar.getExifMetadata()
someVar.getEXIFTag()
someVar.getHeight()
someVar.getIptcMetadata()
someVar.getIPTCTag()
someVar.getWidth()
someVar.grayscale()
someVar.info()
someVar.negative()
someVar.overlay()
someVar.paste()
someVar.resize()
someVar.rotate()
someVar.rotateDrawingAxis()
someVar.scaleToFit()
someVar.setAntialiasing()
someVar.setBackgroundColor()
someVar.setDrawingColor()
someVar.setDrawingStroke()
someVar.setDrawingTransparency()
someVar.sharpen()
someVar.shear()
someVar.shearDrawingAxis()
someVar.translate()
someVar.translateDrawingAxis()
someVar.write()
someVar.writeBase64()
someVar.xorDrawingMode()
someVar.addAutoFilter()
someVar.addColumn()
someVar.addFreezePane()
someVar.addImage()
someVar.addInfo()
someVar.addPageBreaks()
someVar.addRow()
someVar.addRows()
someVar.addSplitPane()
someVar.createSheet()
someVar.deleteColumn()
someVar.deleteColumns()
someVar.deleteRow()
someVar.deleteRows()
someVar.formatCell()
someVar.formatCellRange()
someVar.formatColumn()
someVar.formatColumns()
someVar.formatRow()
someVar.formatRows()
someVar.getCellComment()
someVar.getCellFormula()
someVar.getCellValue()
someVar.getColumnCount()
someVar.info()
someVar.mergeCells()
someVar.readBinary()
someVar.removeSheet()
someVar.setActiveSheet()
someVar.setActiveSheetNumber()
someVar.setCellComment()
someVar.setCellFormula()
someVar.setCellValue()
someVar.setColumnWidth()
someVar.setFooter()
someVar.setHeader()
someVar.setRowHeight()
someVar.shiftColumns()
someVar.shiftRows()
someVar.write()
someVar.duplicate()
someVar.toString()
someVar.append()
someVar.childPos()
someVar.count()
someVar.elemNew()
someVar.getNodeType()
someVar.hasChild()
someVar.keyArray()
someVar.keyList()
someVar.len()
someVar.search()
someVar.transform()
someVar.update()
someVar.len()
someVar.addColumn()
someVar.addRow()
someVar.append()
someVar.clear()
someVar.convertForGrid()
someVar.deleteAt()
someVar.deleteColumn()
someVar.deleteRow()
someVar.each()
someVar.every()
someVar.filter()
someVar.getResult()
someVar.getRow()
someVar.insertAt()
someVar.keyExists()
someVar.map()
someVar.prepend()
someVar.recordCount()
someVar.reduce()
someVar.rowSwap()
someVar.setCell()
someVar.slice()
someVar.some()
someVar.sort()
someVar.toJSON()
someVar.valueArray()
When using Query.cfc, you get your results from the execution by using:
someVar.getResult()
someVar.abs()
someVar.aCos()
someVar.aSin()
someVar.atn()
someVar.bitAnd()
someVar.bitMaskClear()
someVar.bitMaskRead()
someVar.bitMaskSet()
someVar.bitNot()
someVar.bitOr()
someVar.bitSHLN()
someVar.bitSHRN()
someVar.bitXor()
someVar.ceiling()
someVar.cos()
someVar.decrementValue()
someVar.exp()
someVar.fix()
someVar.floor()
someVar.formatBaseN()
someVar.incrementValue()
someVar.inputBaseN()
someVar.log()
someVar.log10()
someVar.max()
someVar.min()
someVar.precisionEvaluate()
someVar.randomize()
someVar.randRange()
someVar.round()
someVar.sgn()
someVar.sin()
someVar.sqr()
someVar.tan()
someVal.booleanFormat()
someVal.yesNoFormat()
These are exclusively member functions and have no headless equivalent. You use them on the Future returned by runAsync
.
FutureObject.cancel()
FutureObject.error(UDFMethod method)
FutureObject.then((UDFMethod method, long timeout)
FutureObject.get()
FutureObject.get(long timeout)
FutureObject.get(long timeout, String timeUnit)
FutureObject.isCancelled()
FutureObject.isDone()
FutureObject.then(UDFMethod method)
FutureObject.then((UDFMethod method, long timeout)
EmptyFutureObject.cancel()
EmptyFutureObject.complete(Object val)
EmptyFutureObject.get()
EmptyFutureObject.isCancelled()
EmptyFutureObject.isDone()
Some member functions might fall into underlying Java methods if the strict ColdFusion syntax is not followed.
Signup for cfbreak
to stay updated on the latest news from the ColdFusion / CFML community. One email, every friday.